Add LeafOutputViewModel and test

This commit is contained in:
2016-03-02 13:02:27 -05:00
parent 659d9b811e
commit c80d048c39
5 changed files with 106 additions and 0 deletions
@@ -0,0 +1,41 @@
using System;
using LeafWeb.Core.Entities;
using LeafWeb.Web.ViewModels.LeafOutput;
using NUnit.Framework;
namespace LeafWeb.Web.Tests.ViewModels.LeafOutput
{
[TestFixture]
public class LeafOutputViewModelTests
{
private LeafInputFile file = new LeafInputFile
{
Filename = "MyFilename.ext",
Id = 3,
CurrentStatus = LeafInputStatusType.Running,
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 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, Is.Empty);
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));
}
}
}
+11
View File
@@ -44,10 +44,21 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\LeafOutput\LeafOutputViewModelTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{25BAED75-7E75-4D11-90D9-358472054DF6}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\Web\Web.csproj">
<Project>{0809033D-DBB9-41AE-8811-9A9CFDFD8966}</Project>
<Name>Web</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -0,0 +1,40 @@
using System.Linq;
using AutoMapper;
namespace LeafWeb.Web.ViewModels.LeafOutput
{
public class LeafOutputViewModel
{
private static readonly IMapper Mapper;
public int LeafInputFileId { get; set; }
public string LeafInputFilename { get; set; }
public string CurrentStatus { get; set; }
public string[] LeafOutputFilenames { get; set; }
public string LeafInputIdentifier { get; set; }
public string LeafInputSiteId { get; set; }
public string LeafInputPhotosynthesisType { get; set; }
static LeafOutputViewModel()
{
var config =
new MapperConfiguration(cfg =>
{
cfg.CreateMap<Core.Entities.LeafInputFile, LeafOutputViewModel>()
.ForMember(dest => dest.LeafInputFileId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.LeafInputFilename, opt => opt.MapFrom(src => src.Filename))
.ForMember(dest => dest.LeafOutputFilenames,
opt => opt.ResolveUsing(file => file.LeafOutputFiles?.Select(o => o.Filename).ToArray() ?? new string[] {}))
.ForMember(dest => dest.LeafInputIdentifier, opt => opt.MapFrom(src => src.LeafInput.Identifier))
.ForMember(dest => dest.LeafInputSiteId, opt => opt.MapFrom(src => src.LeafInput.SiteId))
.ForMember(dest => dest.LeafInputPhotosynthesisType, opt => opt.MapFrom(src => src.LeafInput.PhotosynthesisType.Name));
});
Mapper = config.CreateMapper();
}
public LeafOutputViewModel(Core.Entities.LeafInputFile leafInput)
{
Mapper.Map(leafInput, this);
}
}
}
+12
View File
@@ -0,0 +1,12 @@
@model LeafWeb.Web.ViewModels.LeafOutput.LeafOutputViewModel
@{
ViewBag.Title = "Users";
var grid = new WebGrid(Model, rowsPerPage: 45);
}
<h1>EDO Results</h1>
<div class="row">
</div>
+2
View File
@@ -940,6 +940,7 @@
<Compile Include="Utility\Validation.cs" />
<Compile Include="ViewModels\LeafInput\ConfirmViewModel.cs" />
<Compile Include="ViewModels\LeafInput\CreateViewModel.cs" />
<Compile Include="ViewModels\LeafOutput\LeafOutputViewModel.cs" />
<Compile Include="ViewModels\SelectListViewModel.cs" />
</ItemGroup>
<ItemGroup>
@@ -977,6 +978,7 @@
<Content Include="Views\Shared\_StatusMessage.cshtml" />
<Content Include="Views\Shared\_ValidationField.cshtml" />
<Content Include="Views\Shared\EditorTemplates\SelectListViewModel.cshtml" />
<Content Include="Views\LeafOutput\Index.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>