Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs =================================================================== diff -u -recd4e132deb2683aadc0f83f0853dc1b79602033 -r3beb793b4db2bc773a4ae68783902c359db1e6bb --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs (.../AssemblyCategoryCreator.cs) (revision ecd4e132deb2683aadc0f83f0853dc1b79602033) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssemblyCategoryCreator.cs (.../AssemblyCategoryCreator.cs) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -60,7 +60,7 @@ categoriesOutput => new AssessmentSectionAssemblyCategory( categoriesOutput.LowerLimit, categoriesOutput.UpperLimit, - ConvertAssessmentSectionCategoryGroup(categoriesOutput.Category))).ToArray(); + CreateAssessmentSectionAssemblyCategory(categoriesOutput.Category))).ToArray(); } /// @@ -92,15 +92,15 @@ } /// - /// Converts a into a . + /// Creates a based on . /// /// The to convert. /// A based on . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value, but unsupported. - private static AssessmentSectionAssemblyCategoryGroup ConvertAssessmentSectionCategoryGroup(EAssessmentGrade category) + public static AssessmentSectionAssemblyCategoryGroup CreateAssessmentSectionAssemblyCategory(EAssessmentGrade category) { if (!Enum.IsDefined(typeof(EAssessmentGrade), category)) { Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyCreator.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyCreator.cs (revision 0) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/AssessmentSectionAssemblyCreator.cs (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -0,0 +1,56 @@ +// 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.ComponentModel; +using Assembly.Kernel.Model; +using Ringtoets.AssemblyTool.Data; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Creators +{ + /// + /// Creates instances and + /// values. + /// + internal static class AssessmentSectionAssemblyCreator + { + /// + /// Creates from the given . + /// + /// The result to create the assembly from. + /// The created assembly. + /// Thrown when is null. + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value, but unsupported. + public static AssessmentSectionAssembly CreateAssessmentSectionAssembly(AssessmentSectionAssemblyResult result) + { + if (result == null) + { + throw new ArgumentNullException(nameof(result)); + } + + return new AssessmentSectionAssembly(result.FailureProbability ?? double.NaN, + AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory(result.Category)); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj =================================================================== diff -u -r73961743fdbd1f57320393a37d4b551dc56ff47d -r3beb793b4db2bc773a4ae68783902c359db1e6bb --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 73961743fdbd1f57320393a37d4b551dc56ff47d) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -28,6 +28,7 @@ + Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs =================================================================== diff -u -r9a64bbb28b8179b5894b4bbaf418330a974bf36b -r3beb793b4db2bc773a4ae68783902c359db1e6bb --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (.../AssemblyCategoryCreatorTest.cs) (revision 9a64bbb28b8179b5894b4bbaf418330a974bf36b) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (.../AssemblyCategoryCreatorTest.cs) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -37,6 +37,21 @@ [TestFixture] public class AssemblyCategoryCreatorTest { + private static IEnumerable GetAssessmentSectionAssemblyCategoryGroupConversions + { + get + { + yield return new TestCaseData(EAssessmentGrade.APlus, AssessmentSectionAssemblyCategoryGroup.APlus); + yield return new TestCaseData(EAssessmentGrade.A, AssessmentSectionAssemblyCategoryGroup.A); + yield return new TestCaseData(EAssessmentGrade.B, AssessmentSectionAssemblyCategoryGroup.B); + yield return new TestCaseData(EAssessmentGrade.C, AssessmentSectionAssemblyCategoryGroup.C); + yield return new TestCaseData(EAssessmentGrade.D, AssessmentSectionAssemblyCategoryGroup.D); + yield return new TestCaseData(EAssessmentGrade.Gr, AssessmentSectionAssemblyCategoryGroup.None); + yield return new TestCaseData(EAssessmentGrade.Nvt, AssessmentSectionAssemblyCategoryGroup.NotApplicable); + yield return new TestCaseData(EAssessmentGrade.Ngo, AssessmentSectionAssemblyCategoryGroup.NotAssessed); + } + } + [Test] public void CreateAssessmentSectionAssemblyCategories_CategoryLimitsNull_ThrowsArgumentNullException() { @@ -87,14 +102,7 @@ } [Test] - [TestCase(EAssessmentGrade.APlus, AssessmentSectionAssemblyCategoryGroup.APlus)] - [TestCase(EAssessmentGrade.A, AssessmentSectionAssemblyCategoryGroup.A)] - [TestCase(EAssessmentGrade.B, AssessmentSectionAssemblyCategoryGroup.B)] - [TestCase(EAssessmentGrade.C, AssessmentSectionAssemblyCategoryGroup.C)] - [TestCase(EAssessmentGrade.D, AssessmentSectionAssemblyCategoryGroup.D)] - [TestCase(EAssessmentGrade.Gr, AssessmentSectionAssemblyCategoryGroup.None)] - [TestCase(EAssessmentGrade.Nvt, AssessmentSectionAssemblyCategoryGroup.NotApplicable)] - [TestCase(EAssessmentGrade.Ngo, AssessmentSectionAssemblyCategoryGroup.NotAssessed)] + [TestCaseSource(nameof(GetAssessmentSectionAssemblyCategoryGroupConversions))] public void CreateAssessmentSectionAssemblyCategories_CategoryWithValidAssessmentGrade_ExpectedAssessmentSectionAssemblyCategoryResultType( EAssessmentGrade categoryGroup, AssessmentSectionAssemblyCategoryGroup expectedCategoryGroup) @@ -115,6 +123,36 @@ } [Test] + public void CreateAssessmentSectionAssemblyCategoryGroup_WithInvalidAssessmentGrade_ThrowsInvalidEnumArgumentException() + { + // Setup + var categoryLimits = new[] + { + new AssessmentSectionCategoryLimits((EAssessmentGrade) 99, 0, 0) + }; + + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory((EAssessmentGrade)99); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EAssessmentGrade'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCaseSource(nameof(GetAssessmentSectionAssemblyCategoryGroupConversions))] + public void CreateAssessmentSectionAssemblyCategory_WithValidAssessmentGrade_ExpectedAssessmentSectionAssemblyCategoryResultType( + EAssessmentGrade categoryGroup, + AssessmentSectionAssemblyCategoryGroup expectedCategoryGroup) + { + // Call + AssessmentSectionAssemblyCategoryGroup categoryResult = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory(categoryGroup); + + // Assert + Assert.AreEqual(expectedCategoryGroup, categoryResult); + } + + [Test] public void CreateFailureMechanismSectionAssemblyCategories_CategoryLimitsNull_ThrowsArgumentNullException() { // Call Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyCreatorTest.cs (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -0,0 +1,86 @@ +// 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.ComponentModel; +using Assembly.Kernel.Model; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Creators; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssessmentSectionAssemblyCreatorTest + { + [Test] + public void CreateAssessmentSectionAssemblyWithProbability_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssessmentSectionAssemblyCreator.CreateAssessmentSectionAssembly(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void CreateAssessmentSectionAssemblyWithProbability_WithInvalidEnum_ThrowsInvalidEnumArgumentException() + { + // Setup + var random = new Random(21); + var assemblyResult = new AssessmentSectionAssemblyResult((EAssessmentGrade) 99, random.NextDouble()); + + // Call + TestDelegate test = () => AssessmentSectionAssemblyCreator.CreateAssessmentSectionAssembly(assemblyResult); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EAssessmentGrade'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCase(EAssessmentGrade.APlus, AssessmentSectionAssemblyCategoryGroup.APlus)] + [TestCase(EAssessmentGrade.A, AssessmentSectionAssemblyCategoryGroup.A)] + [TestCase(EAssessmentGrade.B, AssessmentSectionAssemblyCategoryGroup.B)] + [TestCase(EAssessmentGrade.C, AssessmentSectionAssemblyCategoryGroup.C)] + [TestCase(EAssessmentGrade.D, AssessmentSectionAssemblyCategoryGroup.D)] + [TestCase(EAssessmentGrade.Gr, AssessmentSectionAssemblyCategoryGroup.None)] + [TestCase(EAssessmentGrade.Nvt, AssessmentSectionAssemblyCategoryGroup.NotApplicable)] + [TestCase(EAssessmentGrade.Ngo, AssessmentSectionAssemblyCategoryGroup.NotAssessed)] + public void CreateAssessmentSectionAssemblyWithProbability_WithValidEnum_ReturnsExpectedValues(EAssessmentGrade originalGroup, + AssessmentSectionAssemblyCategoryGroup expectedGroup) + { + // Setup + var random = new Random(21); + double probability = random.NextDouble(); + var assemblyResult = new AssessmentSectionAssemblyResult(originalGroup, probability); + + // Call + AssessmentSectionAssembly result = AssessmentSectionAssemblyCreator.CreateAssessmentSectionAssembly(assemblyResult); + + // Assert + Assert.AreEqual(probability, result.Probability); + Assert.AreEqual(expectedGroup, result.Group); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj =================================================================== diff -u -r73961743fdbd1f57320393a37d4b551dc56ff47d -r3beb793b4db2bc773a4ae68783902c359db1e6bb --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 73961743fdbd1f57320393a37d4b551dc56ff47d) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) @@ -30,6 +30,7 @@ +