From 1d525a49d0a25c2a79d42027db6d88328a8ee2ff Mon Sep 17 00:00:00 2001 From: Michael Schnyder Date: Mon, 5 Jun 2017 19:30:49 +0200 Subject: [PATCH] added test that shows that a couple of JobRunStates are missing and have shifted. relates to #42 --- .../Jobbr.Tests/Integration/MappingTests.cs | 46 +++++++++++++++++++ source/Jobbr.Tests/Jobbr.Tests.csproj | 1 + 2 files changed, 47 insertions(+) create mode 100644 source/Jobbr.Tests/Integration/MappingTests.cs diff --git a/source/Jobbr.Tests/Integration/MappingTests.cs b/source/Jobbr.Tests/Integration/MappingTests.cs new file mode 100644 index 0000000..cdcd4b2 --- /dev/null +++ b/source/Jobbr.Tests/Integration/MappingTests.cs @@ -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(); + + 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)); + + } + } +} diff --git a/source/Jobbr.Tests/Jobbr.Tests.csproj b/source/Jobbr.Tests/Jobbr.Tests.csproj index 96e146f..374473f 100644 --- a/source/Jobbr.Tests/Jobbr.Tests.csproj +++ b/source/Jobbr.Tests/Jobbr.Tests.csproj @@ -92,6 +92,7 @@ +