171 lines
6.6 KiB
C#
171 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using LeafWeb.Core.Entities;
|
|
using LeafWeb.WebCms.App_Start;
|
|
using LeafWeb.WebCms.Models;
|
|
using NUnit.Framework;
|
|
|
|
namespace LeafWeb.WebCms.Tests.Models
|
|
{
|
|
[TestFixture]
|
|
public class LeafInputDetailsTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
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 viewModel = new LeafInputDataCurveViewModel(leafInputDataCurve);
|
|
|
|
Assert.That(viewModel.CO2S, Is.EqualTo(3.1));
|
|
}
|
|
|
|
[Test]
|
|
public void CanConstructLeafInputData()
|
|
{
|
|
var leafInputData = 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));
|
|
}
|
|
|
|
[Test]
|
|
public void CanConstructFromLeafInputFile()
|
|
{
|
|
var leafInput = GetLeafInput;
|
|
var viewModel = new LeafInputDetails(leafInput);
|
|
|
|
//Assert.That(viewModel.CurrentStatus, Is.EqualTo(leafInput.CurrentStatus.ToString()));
|
|
Assert.That(viewModel.StatusHistory, Has.Count.EqualTo(5));
|
|
Assert.That(viewModel.StatusHistory[0].Status, Is.EqualTo("Pending"));
|
|
Assert.That(viewModel.StatusHistory[1].Status, Is.EqualTo("Starting"));
|
|
Assert.That(viewModel.StatusHistory[4].Status, Is.EqualTo("Complete"));
|
|
//Assert.That(viewModel., Is.EqualTo(leafInput.Id));
|
|
//Assert.That(viewModel.LeafOutputFilenames, Has.Length.EqualTo(1));
|
|
//Assert.That(viewModel., Is.EqualTo(leafInput.Identifier));
|
|
Assert.That(viewModel.SiteId, Is.EqualTo(leafInput.SiteId));
|
|
//Assert.That(viewModel.LeafInputPhotosynthesisType, Is.EqualTo(leafInput.PhotosynthesisType.Name));
|
|
|
|
Assert.That(viewModel.LeafInputData, Has.Count.EqualTo(1));
|
|
Assert.That(viewModel.LeafInputData[0].SiteName, Is.EqualTo("MySite"));
|
|
Assert.That(viewModel.LeafInputData[0].Id, Is.EqualTo(123));
|
|
|
|
Assert.That(viewModel.LeafInputData[0].Site, Is.Not.Null);
|
|
Assert.That(viewModel.LeafInputData[0].Site.SiteId, Is.EqualTo("MySiteId"));
|
|
Assert.That(viewModel.LeafInputData[0].Site.Latitude, Is.EqualTo(10));
|
|
Assert.That(viewModel.LeafInputData[0].Site.Longitude, Is.EqualTo(20));
|
|
Assert.That(viewModel.LeafInputData[0].Site.Elevation, Is.Null);
|
|
|
|
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].Id, Is.EqualTo(123));
|
|
}
|
|
|
|
}
|
|
} |