Skip to content

Commit

Permalink
added test that shows that a couple of JobRunStates are missing and h…
Browse files Browse the repository at this point in the history
…ave shifted. relates to #42
  • Loading branch information
michaelschnyder committed Jun 5, 2017
1 parent eae67e1 commit 1d525a4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions source/Jobbr.Tests/Integration/MappingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Jobbr.Tests.Integration
{
[TestClass]
public class MappingTests
{
[TestMethod]
public void CoreRunStateNames_IfExistInComponentModels_NameHasSameValue()
{
var coreType = typeof(Jobbr.Server.Core.Models.JobRunStates);
var coreMembers = Enum.GetNames(coreType);

var errors = new List<string>();

var allJobJobRunEnumTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(asm => asm.GetTypes().Where(t => t.Namespace != null && t.IsEnum && t.Namespace.Contains("ComponentModel")));

foreach (var enumType in allJobJobRunEnumTypes)
{
var remoteMembers = Enum.GetNames(enumType);

foreach (var coreName in coreMembers)
{
if (remoteMembers.Contains(coreName))
{
// AutoMapper maps by using the index/value of the enum so we do
var coreValue = (int)Enum.Parse(coreType, coreName);
var remoteVaue = (int)Enum.Parse(enumType, coreName);

if (remoteVaue != coreValue)
{
var err = $"{enumType.FullName} contains a member for {coreName} but its value is different. CoreValue: {coreValue}, RemoteValue: {remoteVaue}";
errors.Add(err);
}
}
}
}

Assert.AreEqual(0, errors.Count, $"One or more errors found while comparing component model values for {coreType}\n\n" + string.Join("\n", errors));

}
}
}
1 change: 1 addition & 0 deletions source/Jobbr.Tests/Jobbr.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Integration\Execution\ProgressChannelTests.cs" />
<Compile Include="Integration\Management\JobManagementTests.cs" />
<Compile Include="Integration\Management\JobQueryServiceTests.cs" />
<Compile Include="Integration\MappingTests.cs" />
<Compile Include="Integration\Startup\BadEnvironmentTests.cs" />
<Compile Include="Integration\Startup\ConfigurationValidationTests.cs" />
<Compile Include="Integration\Startup\SetupValidationTests.cs" />
Expand Down

0 comments on commit 1d525a4

Please sign in to comment.