Search for both LeafInput and LeafInputData

This commit is contained in:
2023-02-02 09:35:22 -05:00
parent 8e16510ad9
commit 680f139aa5
24 changed files with 808 additions and 281 deletions
@@ -0,0 +1,30 @@
using System.Linq;
using LeafWeb.WebCms.App_Start;
using LeafWeb.WebCms.Models;
using NUnit.Framework;
namespace LeafWeb.WebCms.Tests.Models
{
[TestFixture]
public class LeafDataResultViewModelTests
{
[SetUp]
public void SetUp()
{
AutoMapperConfig.RegisterMappings();
}
[Test]
public void CanConstruct_LeafDataResultViewModel()
{
var leafInputData = LeafInputTestData.GetLeafInputData;
var viewModel = new LeafDataResultViewModel(leafInputData);
Assert.That(viewModel.SiteId, Is.EqualTo(leafInputData.Site.SiteId));
Assert.That(viewModel.SpeciesSampled, Is.EqualTo(leafInputData.Site.SpeciesSampled));
Assert.That(viewModel.Latitude, Is.EqualTo(10));
Assert.That(viewModel.Longitude, Is.EqualTo(20));
//Assert.That(viewModel.CO2S, Is.EqualTo(leafInputData.Data.First().CO2S));
}
}
}
+8 -107
View File
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using LeafWeb.Core.Entities;
using LeafWeb.WebCms.App_Start;
using LeafWeb.WebCms.App_Start;
using LeafWeb.WebCms.Models;
using NUnit.Framework;
@@ -16,106 +13,10 @@ namespace LeafWeb.WebCms.Tests.Models
AutoMapperConfig.RegisterMappings();
}
private LeafInput GetLeafInput =>
new LeafInput
{
CurrentStatus = LeafInputStatusType.Complete,
OutputFiles = new[] {new LeafOutputFile {Filename = "OutputFilename.txt"}},
Added = DateTime.Today,
Email = "test@email.com",
Identifier = "Ident I Fier",
Name = "My Name",
PhotosynthesisType = new PhotosynthesisType {Id = "1", Name = "1", SortOrder = 1},
InputFiles = new[]
{
new LeafInputFile
{
Filename = "MyFilename.ext",
Id = 3
}
},
StatusHistory = new List<LeafInputStatus>
{
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(4, 0, 0)),
Description = "Added",
Details = "Uploaded from Web",
Id = 1,
Status = LeafInputStatusType.Pending
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(3, 0, 0)),
Description = "Uploading input data",
Id = 2,
Status = LeafInputStatusType.Starting
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(2, 12, 0)),
Description = "Running on server",
Id = 3,
Status = LeafInputStatusType.Running
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(1, 0, 0)),
Description = "Downloading results",
Id = 4,
Status = LeafInputStatusType.Finishing
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(0, 12, 0)),
Description = "All done",
Id = 5,
Status = LeafInputStatusType.Complete
}
},
LeafInputData = new List<LeafInputData>
{
new LeafInputData
{
Site = new LeafInputDataSite {Latitude = 10, Longitude = 20, SiteId = "MySiteId"},
SiteName = "MySite",
Id = 123,
Data = new List<LeafInputDataCurve>
{
new LeafInputDataCurve
{
CO2S = 3.1
}
}
}
}
};
private LeafInputData GetLeafInputData =>
new LeafInputData
{
Site = new LeafInputDataSite {Latitude = 10, Longitude = 20, SiteId = "MySiteId"},
SiteName = "MySite",
Id = 123,
Data = new List<LeafInputDataCurve>
{
new LeafInputDataCurve
{
CO2S = 3.1
}
}
};
private LeafInputDataCurve GetLeafInputDataCurve =>
new LeafInputDataCurve
{
CO2S = 3.1
};
[Test]
public void CanConstructLeafInputDataCurve()
{
var leafInputDataCurve = GetLeafInputDataCurve;
var leafInputDataCurve = LeafInputTestData.GetLeafInputDataCurve;
var viewModel = new LeafInputDataCurveViewModel(leafInputDataCurve);
Assert.That(viewModel.CO2S, Is.EqualTo(3.1));
@@ -124,19 +25,19 @@ namespace LeafWeb.WebCms.Tests.Models
[Test]
public void CanConstructLeafInputData()
{
var leafInputData = GetLeafInputData;
var leafInputData = LeafInputTestData.GetLeafInputData;
var viewModel = new LeafInputDataViewModel(leafInputData);
Assert.That(viewModel.SiteName, Is.EqualTo("MySite"));
Assert.That(viewModel.Data, Is.Not.Null);
Assert.That(viewModel.Data, Has.Count.GreaterThan(0));
Assert.That(viewModel.Data[0].CO2S, Is.EqualTo(3.1));
Assert.That(viewModel.Data[0].CO2S, Is.EqualTo(292.5618317));
}
[Test]
public void CanConstructAdminFromLeafInputFile()
{
var leafInput = GetLeafInput;
var leafInput = LeafInputTestData.GetLeafInput;
var viewModel = new LeafInputDetails_Admin(leafInput);
//Assert.That(viewModel.CurrentStatus, Is.EqualTo(leafInput.CurrentStatus.ToString()));
@@ -162,7 +63,7 @@ namespace LeafWeb.WebCms.Tests.Models
Assert.That(viewModel.LeafInputData[0].Data, Is.Not.Null);
Assert.That(viewModel.LeafInputData[0].Data, Has.Count.GreaterThan(0));
Assert.That(viewModel.LeafInputData[0].Data[0].CO2S, Is.EqualTo(3.1));
Assert.That(viewModel.LeafInputData[0].Data[1].CO2S, Is.EqualTo(195.4142136));
//Assert.That(viewModel.LeafInputData[0].Id, Is.EqualTo(123));
}
@@ -170,7 +71,7 @@ namespace LeafWeb.WebCms.Tests.Models
[Test]
public void CanConstructFromLeafInputFile()
{
var leafInput = GetLeafInput;
var leafInput = LeafInputTestData.GetLeafInput;
var viewModel = new LeafInputDetails(leafInput);
//Assert.That(viewModel.CurrentStatus, Is.EqualTo(leafInput.CurrentStatus.ToString()));
@@ -192,7 +93,7 @@ namespace LeafWeb.WebCms.Tests.Models
Assert.That(viewModel.LeafInputData[0].Data, Is.Not.Null);
Assert.That(viewModel.LeafInputData[0].Data, Has.Count.GreaterThan(0));
Assert.That(viewModel.LeafInputData[0].Data[0].CO2S, Is.EqualTo(3.1));
Assert.That(viewModel.LeafInputData[0].Data[0].CO2S, Is.EqualTo(292.5618317));
//Assert.That(viewModel.LeafInputData[0].Id, Is.EqualTo(123));
}
+120
View File
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using LeafWeb.Core.Entities;
namespace LeafWeb.WebCms.Tests.Models
{
public static class LeafInputTestData
{
public static LeafInput GetLeafInput =>
new LeafInput
{
CurrentStatus = LeafInputStatusType.Complete,
OutputFiles = new[] {new LeafOutputFile {Filename = "OutputFilename.txt"}},
Added = DateTime.Today,
Email = "test@email.com",
Identifier = "Ident I Fier",
Name = "My Name",
PhotosynthesisType = new PhotosynthesisType {Id = "1", Name = "1", SortOrder = 1},
InputFiles = new[]
{
new LeafInputFile
{
Filename = "MyFilename.ext",
Id = 3
}
},
StatusHistory = new List<LeafInputStatus>
{
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(4, 0, 0)),
Description = "Added",
Details = "Uploaded from Web",
Id = 1,
Status = LeafInputStatusType.Pending
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(3, 0, 0)),
Description = "Uploading input data",
Id = 2,
Status = LeafInputStatusType.Starting
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(2, 12, 0)),
Description = "Running on server",
Id = 3,
Status = LeafInputStatusType.Running
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(1, 0, 0)),
Description = "Downloading results",
Id = 4,
Status = LeafInputStatusType.Finishing
},
new LeafInputStatus
{
DateTime = DateTime.Today.Subtract(new TimeSpan(0, 12, 0)),
Description = "All done",
Id = 5,
Status = LeafInputStatusType.Complete
}
},
LeafInputData = new List<LeafInputData>
{
new LeafInputData
{
Site = SampleLeafInputDataSite,
SiteName = "MySite",
Id = 123,
Data = GetLeafInputDataCurves
}
}
};
public static LeafInputData GetLeafInputData =>
new LeafInputData
{
Site = SampleLeafInputDataSite,
SiteName = "MySite",
Id = 123,
Data = GetLeafInputDataCurves
};
public static List<LeafInputDataCurve> GetLeafInputDataCurves =>
new List<LeafInputDataCurve> {
new LeafInputDataCurve{ CO2S=292.5618317, PARi=993.0888855, Tleaf=23.53769627, PhiPS2=0.180769687 },
new LeafInputDataCurve{ CO2S=195.4142136, PARi=992.5410278, Tleaf=23.68962097, PhiPS2=0.163288942 },
new LeafInputDataCurve{ CO2S=146.4719864, PARi=992.1625671, Tleaf=23.90329285, PhiPS2=0.147352806 },
new LeafInputDataCurve{ CO2S=98.51480789, PARi=991.761908, Tleaf=24.21637478, PhiPS2=0.130597749 },
new LeafInputDataCurve{ CO2S=73.31520309, PARi=991.5204651, Tleaf=24.19524651, PhiPS2=0.122154858 },
new LeafInputDataCurve{ CO2S=49.07753906, PARi=991.50896, Tleaf=24.11649742, PhiPS2=0.11011836 },
new LeafInputDataCurve{ CO2S=389.8589264, PARi=991.5494934, Tleaf=23.77918701, PhiPS2=0.183856114 },
new LeafInputDataCurve{ CO2S=587.4440186, PARi=990.6557251, Tleaf=23.97962074, PhiPS2=0.224674063 },
new LeafInputDataCurve{ CO2S=783.7866455, PARi=990.5349609, Tleaf=24.24497566, PhiPS2=0.241833394 },
new LeafInputDataCurve{ CO2S=981.9117737, PARi=990.3832764, Tleaf=24.27973061, PhiPS2=0.250284039 },
new LeafInputDataCurve{ CO2S=1181.568982, PARi=990.2308533, Tleaf=24.49090347, PhiPS2=0.252074273 },
new LeafInputDataCurve{ CO2S=1379.865356, PARi=990.0950989, Tleaf=24.66598072, PhiPS2=0.25113703 },
new LeafInputDataCurve{ CO2S=1579.277905, PARi=989.9327454, Tleaf=24.77762184, PhiPS2=0.252735204 },
new LeafInputDataCurve{ CO2S=1977.797449, PARi=989.8097778, Tleaf=24.84818077, PhiPS2=0.248197252 },
};
public static LeafInputDataCurve GetLeafInputDataCurve =>
new LeafInputDataCurve
{
CO2S = 3.1,
PARi = 1.1,
};
public static LeafInputDataSite SampleLeafInputDataSite => new LeafInputDataSite
{
Latitude = 10,
Longitude = 20,
SiteId = "MySiteId",
SpeciesSampled = "Maple"
};
}
}