05b2bfefb1
Error handling for Piscal processing
80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using LeafWeb.Core.Entities;
|
|
using LeafWeb.Web.ViewModels.LeafOutput;
|
|
using NUnit.Framework;
|
|
|
|
namespace LeafWeb.Web.Tests.ViewModels.LeafOutput
|
|
{
|
|
[TestFixture]
|
|
public class LeafOutputViewModelTests
|
|
{
|
|
private LeafInputFile GetLeafInputFile()
|
|
{
|
|
return new LeafInputFile
|
|
{
|
|
Filename = "MyFilename.ext",
|
|
Id = 3,
|
|
CurrentStatus = LeafInputStatusType.Complete,
|
|
LeafInput = new LeafInput
|
|
{
|
|
Added = DateTime.Today,
|
|
Email = "test@email.com",
|
|
Identifier = "Ident I Fier",
|
|
Name = "My Name",
|
|
PhotosynthesisType = new PhotosynthesisType {Id = "1", Name = "1", SortOrder = 1}
|
|
},
|
|
LeafOutputFiles = new[] {new LeafOutputFile {Filename = "OutputFilename.txt"}}
|
|
};
|
|
}
|
|
|
|
[Test]
|
|
public void CanConstructFromLeafInputFile()
|
|
{
|
|
var file = GetLeafInputFile();
|
|
var viewModel = new LeafOutputViewModel(file);
|
|
|
|
Assert.That(viewModel.CurrentStatus, Is.EqualTo(file.CurrentStatus.ToString()));
|
|
Assert.That(viewModel.LeafInputFileId, Is.EqualTo(file.Id));
|
|
Assert.That(viewModel.LeafInputFilename, Is.EqualTo(file.Filename));
|
|
Assert.That(viewModel.LeafOutputFilenames, Has.Length.EqualTo(1));
|
|
Assert.That(viewModel.LeafInputIdentifier, Is.EqualTo(file.LeafInput.Identifier));
|
|
Assert.That(viewModel.LeafInputSiteId, Is.EqualTo(file.LeafInput.SiteId));
|
|
Assert.That(viewModel.LeafInputPhotosynthesisType, Is.EqualTo(file.LeafInput.PhotosynthesisType.Name));
|
|
}
|
|
|
|
[Test]
|
|
public void CanConstructFromLeafInputFile_Running()
|
|
{
|
|
var file = GetLeafInputFile();
|
|
file.CurrentStatus = LeafInputStatusType.Running;
|
|
file.LeafOutputFiles = new LeafOutputFile[0];
|
|
var viewModel = new LeafOutputViewModel(file);
|
|
|
|
Assert.That(viewModel.CurrentStatus, Is.EqualTo(LeafInputStatusType.Running.ToString()));
|
|
Assert.That(viewModel.LeafOutputFilenames, Has.Length.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void CanConstructFromLeafInputFile_Error()
|
|
{
|
|
var file = GetLeafInputFile();
|
|
file.CurrentStatus = LeafInputStatusType.Error;
|
|
file.StatusHistory = new []
|
|
{
|
|
new LeafInputFileStatus
|
|
{
|
|
DateTime = DateTime.Today,
|
|
LeafInputFile = file,
|
|
Description = "My Error",
|
|
Status = LeafInputStatusType.Error
|
|
}
|
|
};
|
|
var viewModel = new LeafOutputViewModel(file);
|
|
|
|
Assert.That(viewModel.CurrentStatus, Is.EqualTo(LeafInputStatusType.Error.ToString()));
|
|
Assert.That(viewModel.ErrorMessages[0], Is.EqualTo(file.StatusHistory.First().Description));
|
|
}
|
|
}
|
|
}
|