Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs =================================================================== diff -u -rc1069e6cf39338685915adbe417b2bfa28e3ac22 -r19fd80cc583267703afacd8eb812d170d3282fa0 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs (.../AssemblyCategoriesCalculator.cs) (revision c1069e6cf39338685915adbe417b2bfa28e3ac22) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs (.../AssemblyCategoriesCalculator.cs) (revision 19fd80cc583267703afacd8eb812d170d3282fa0) @@ -61,7 +61,7 @@ ICategoriesCalculator kernel = factory.CreateAssemblyCategoriesKernel(); CalculationOutput output = kernel.CalculateAssessmentSectionCategories(input); - return AssessmentSectionAssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(output); + return AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(output); } catch (Exception e) { Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs (revision 0) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs (revision 19fd80cc583267703afacd8eb812d170d3282fa0) @@ -0,0 +1,98 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using AssemblyTool.Kernel; +using AssemblyTool.Kernel.Data.AssemblyCategories; +using Ringtoets.Common.Data.AssemblyTool; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Creators +{ + /// + /// Creates instances. + /// + internal static class AssemblyCategoryCreator + { + /// + /// Creates an + /// based on the information given in the . + /// + /// The output to create the result for. + /// An + /// with information taken from the . + /// Thrown when is null. + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value, but unsupported. + public static IEnumerable CreateAssessmentSectionAssemblyCategories( + CalculationOutput output) + { + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + + return output.Result.Select( + categoriesOutput => new AssessmentSectionAssemblyCategory(categoriesOutput.LowerBoundary, + categoriesOutput.UpperBoundary, + ConvertAssessmentSectionCategoryGroup(categoriesOutput.CategoryGroup))).ToArray(); + } + + /// + /// Converts a into a . + /// + /// The to convert. + /// A based on . + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value, but unsupported. + private static AssessmentSectionAssemblyCategoryGroup ConvertAssessmentSectionCategoryGroup(AssessmentSectionCategoryGroup category) + { + if (!Enum.IsDefined(typeof(AssessmentSectionCategoryGroup), category)) + { + throw new InvalidEnumArgumentException(nameof(category), + (int) category, + typeof(AssessmentSectionCategoryGroup)); + } + + switch (category) + { + case AssessmentSectionCategoryGroup.APlus: + return AssessmentSectionAssemblyCategoryGroup.APlus; + case AssessmentSectionCategoryGroup.A: + return AssessmentSectionAssemblyCategoryGroup.A; + case AssessmentSectionCategoryGroup.B: + return AssessmentSectionAssemblyCategoryGroup.B; + case AssessmentSectionCategoryGroup.C: + return AssessmentSectionAssemblyCategoryGroup.C; + case AssessmentSectionCategoryGroup.D: + return AssessmentSectionAssemblyCategoryGroup.D; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Fisheye: Tag 19fd80cc583267703afacd8eb812d170d3282fa0 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyCategoryCreator.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj =================================================================== diff -u -r39e13825618c9845e2100ae802a007c04c2e8517 -r19fd80cc583267703afacd8eb812d170d3282fa0 --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 39e13825618c9845e2100ae802a007c04c2e8517) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 19fd80cc583267703afacd8eb812d170d3282fa0) @@ -22,7 +22,7 @@ - + Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (revision 19fd80cc583267703afacd8eb812d170d3282fa0) @@ -0,0 +1,114 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using AssemblyTool.Kernel; +using AssemblyTool.Kernel.Data; +using AssemblyTool.Kernel.Data.AssemblyCategories; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.Creators; +using Ringtoets.Common.Data.AssemblyTool; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssemblyCategoryCreatorTest + { + [Test] + public void CreateAssessmentSectionAssemblyCategories_OutputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_WithOutput_ReturnAssessmentSectionAssemblyCategoryResult() + { + // Setup + var random = new Random(11); + + var output = new CalculationOutput(new[] + { + new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(output); + + // Assert + AssessmentSectionAssemblyCategoryAssert.AssertAssessmentSectionAssemblyCategories(output, result); + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_CategoryWithInvalidAssessmentSectionAssemblyCategory_ThrowsInvalidEnumArgumentException() + { + // Setup + var output = new CalculationOutput(new[] + { + new AssessmentSectionCategory((AssessmentSectionCategoryGroup) 99, new Probability(0), new Probability(0)) + }); + + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(output); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'AssessmentSectionCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCase(AssessmentSectionCategoryGroup.APlus, AssessmentSectionAssemblyCategoryGroup.APlus)] + [TestCase(AssessmentSectionCategoryGroup.A, AssessmentSectionAssemblyCategoryGroup.A)] + [TestCase(AssessmentSectionCategoryGroup.B, AssessmentSectionAssemblyCategoryGroup.B)] + [TestCase(AssessmentSectionCategoryGroup.C, AssessmentSectionAssemblyCategoryGroup.C)] + [TestCase(AssessmentSectionCategoryGroup.D, AssessmentSectionAssemblyCategoryGroup.D)] + public void CreateAssessmentSectionAssemblyCategories_CategoryWithValidAssessmentSectionAssemblyCategory_ExpectedAssessmentSectionAssemblyCategoryResultType( + AssessmentSectionCategoryGroup categoryGroup, + AssessmentSectionAssemblyCategoryGroup expectedCategoryGroup) + { + // Setup + var output = new CalculationOutput(new[] + { + new AssessmentSectionCategory(categoryGroup, new Probability(0), new Probability(0)) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(output); + + // Assert + Assert.AreEqual(1, result.Count()); + AssessmentSectionAssemblyCategory categoryResult = result.First(); + + Assert.AreEqual(expectedCategoryGroup, categoryResult.Group); + } + } +} \ No newline at end of file Fisheye: Tag 19fd80cc583267703afacd8eb812d170d3282fa0 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyCategoryCreatorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj =================================================================== diff -u -r39e13825618c9845e2100ae802a007c04c2e8517 -r19fd80cc583267703afacd8eb812d170d3282fa0 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 39e13825618c9845e2100ae802a007c04c2e8517) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 19fd80cc583267703afacd8eb812d170d3282fa0) @@ -26,7 +26,7 @@ - +