Index: Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -0,0 +1,109 @@ +// 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 Ringtoets.AssemblyTool.Data.Output; +using Ringtoets.Common.Data.AssemblyTool; + +namespace Ringtoets.Common.Service.AssemblyTool +{ + /// + /// Converter to convert into . + /// + public static class AssemblyCategoryConverter + { + /// + /// Converts a list of into a list of . + /// + /// The result to convert. + /// The converted categories. + /// Thrown when is null. + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value but unsupported. + public static IEnumerable ConvertAssessmentSectionAssemblyCategories( + IEnumerable result) + { + if (result == null) + { + throw new ArgumentNullException(nameof(result)); + } + + return result.Select(ConvertAssessmentSectionAssemblyCategory).ToArray(); + } + + /// + /// Converts into . + /// + /// The result to convert. + /// The converted category. + /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value but unsupported. + private static AssessmentSectionAssemblyCategory ConvertAssessmentSectionAssemblyCategory(AssessmentSectionAssemblyCategoryResult result) + { + return new AssessmentSectionAssemblyCategory(result.LowerBoundary, result.UpperBoundary, + ConvertAssessmentSectionAssemblyCategoryType(result.Category)); + } + + /// + /// Converts into + /// . + /// + /// The category type to convert. + /// The converted category type. + /// /// Thrown when + /// is an invalid value. + /// Thrown when + /// is a valid value but unsupported. + private static AssessmentSectionAssemblyCategoryType ConvertAssessmentSectionAssemblyCategoryType( + AssessmentSectionAssemblyCategoryResultType categoryType) + { + if (!Enum.IsDefined(typeof(AssessmentSectionAssemblyCategoryResultType), categoryType)) + { + throw new InvalidEnumArgumentException(nameof(categoryType), + (int) categoryType, + typeof(AssessmentSectionAssemblyCategoryResultType)); + } + + switch (categoryType) + { + case AssessmentSectionAssemblyCategoryResultType.APlus: + return AssessmentSectionAssemblyCategoryType.APlus; + case AssessmentSectionAssemblyCategoryResultType.A: + return AssessmentSectionAssemblyCategoryType.A; + case AssessmentSectionAssemblyCategoryResultType.B: + return AssessmentSectionAssemblyCategoryType.B; + case AssessmentSectionAssemblyCategoryResultType.C: + return AssessmentSectionAssemblyCategoryType.C; + case AssessmentSectionAssemblyCategoryResultType.D: + return AssessmentSectionAssemblyCategoryType.D; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryInputConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryInputConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryInputConverter.cs (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -0,0 +1,49 @@ +// 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 Ringtoets.AssemblyTool.Data.Input; +using Ringtoets.Common.Data.AssemblyTool; + +namespace Ringtoets.Common.Service.AssemblyTool +{ + /// + /// Converter to convert into . + /// + public static class AssemblyCategoryInputConverter + { + /// + /// Converts into . + /// + /// The input to convert. + /// The converted calculator input. + /// Thrown when is null. + public static AssemblyCategoriesCalculatorInput Convert(AssemblyCategoryInput input) + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + return new AssemblyCategoriesCalculatorInput(input.SignalingNorm, input.LowerBoundaryNorm); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -r8c111accea72ca8a9205a8615102e16168f62ce7 --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -15,6 +15,8 @@ + + @@ -68,6 +70,16 @@ Core.Common.Util False + + {420ed9c3-0c33-47ea-b893-121a9c0db4f1} + Ringtoets.AssemblyTool.Data + False + + + {358b6da2-a1df-477f-b6ac-c30204265cb0} + Ringtoets.AssemblyTool.KernelWrapper + False + {888D4097-8BC2-4703-9FB1-8744C94D525E} Ringtoets.HydraRing.Calculation Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -0,0 +1,112 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data.Output; +using Ringtoets.Common.Data.AssemblyTool; +using Ringtoets.Common.Service.AssemblyTool; + +namespace Ringtoets.Common.Service.Test.AssemblyTool +{ + [TestFixture] + public class AssemblyCategoryConverterTest + { + [Test] + public void ConvertAssessmentSectionAssemblyCategories_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void ConvertAssessmentSectionAssemblyCategories_WithResult_ReturnAssessmentSectionAssemblyCategories() + { + // Setup + var random = new Random(11); + var result = new[] + { + new AssessmentSectionAssemblyCategoryResult(random.NextDouble(), random.NextDouble(), random.NextEnumValue()), + new AssessmentSectionAssemblyCategoryResult(random.NextDouble(), random.NextDouble(), random.NextEnumValue()), + new AssessmentSectionAssemblyCategoryResult(random.NextDouble(), random.NextDouble(), random.NextEnumValue()) + }; + + // Call + IEnumerable categories = AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(result); + + // Assert + Assert.AreEqual(result.Length, categories.Count()); + CollectionAssert.AreEqual(result.Select(r => r.LowerBoundary), categories.Select(c => c.LowerBoundary)); + CollectionAssert.AreEqual(result.Select(r => r.UpperBoundary), categories.Select(c => c.UpperBoundary)); + } + + [Test] + public void ConvertAssessmentSectionAssemblyCategories_CategoryWithInvalidType_ThrowsInvalidEnumArgumentException() + { + // Setup + var result = new[] + { + new AssessmentSectionAssemblyCategoryResult(0, 0, (AssessmentSectionAssemblyCategoryResultType) 99) + }; + + // Call + TestDelegate test = () => AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(result); + + // Assert + const string expectedMessage = "The value of argument 'categoryType' (99) is invalid for Enum type 'AssessmentSectionAssemblyCategoryResultType'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(AssessmentSectionAssemblyCategoryResultType.APlus, AssessmentSectionAssemblyCategoryType.APlus)] + [TestCase(AssessmentSectionAssemblyCategoryResultType.A, AssessmentSectionAssemblyCategoryType.A)] + [TestCase(AssessmentSectionAssemblyCategoryResultType.B, AssessmentSectionAssemblyCategoryType.B)] + [TestCase(AssessmentSectionAssemblyCategoryResultType.C, AssessmentSectionAssemblyCategoryType.C)] + [TestCase(AssessmentSectionAssemblyCategoryResultType.D, AssessmentSectionAssemblyCategoryType.D)] + public void ConvertAssessmentSectionAssemblyCategories_CategoryWithValidType_ExpectedAssessmentSectionAssemblyCategoryType( + AssessmentSectionAssemblyCategoryResultType resultType, + AssessmentSectionAssemblyCategoryType expectedType) + { + // Setup + var result = new[] + { + new AssessmentSectionAssemblyCategoryResult(0, 0, resultType) + }; + + // Call + IEnumerable categories = AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(result); + + // Assert + Assert.AreEqual(1, categories.Count()); + AssessmentSectionAssemblyCategory category = categories.First(); + + Assert.AreEqual(expectedType, category.Type); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryInputConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryInputConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryInputConverterTest.cs (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -0,0 +1,62 @@ +// 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 NUnit.Framework; +using Ringtoets.AssemblyTool.Data.Input; +using Ringtoets.Common.Data.AssemblyTool; +using Ringtoets.Common.Service.AssemblyTool; + +namespace Ringtoets.Common.Service.Test.AssemblyTool +{ + [TestFixture] + public class AssemblyCategoryInputConverterTest + { + [Test] + public void Convert_InputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryInputConverter.Convert(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("input", exception.ParamName); + } + + [Test] + public void Convert_WithInput_ReturnsCalculatorInput() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerBoundaryNorm = random.NextDouble(); + + var input = new AssemblyCategoryInput(signalingNorm, lowerBoundaryNorm); + + // Call + AssemblyCategoriesCalculatorInput calculatorInput = AssemblyCategoryInputConverter.Convert(input); + + // Assert + Assert.AreEqual(signalingNorm, calculatorInput.SignalingNorm); + Assert.AreEqual(lowerBoundaryNorm, calculatorInput.LowerBoundaryNorm); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r8c111accea72ca8a9205a8615102e16168f62ce7 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision ac96d7c315129af851634ed5a4a6800b59ede718) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 8c111accea72ca8a9205a8615102e16168f62ce7) @@ -27,6 +27,8 @@ + + @@ -80,6 +82,18 @@ {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {420ed9c3-0c33-47ea-b893-121a9c0db4f1} + Ringtoets.AssemblyTool.Data + + + {358b6da2-a1df-477f-b6ac-c30204265cb0} + Ringtoets.AssemblyTool.KernelWrapper + + + {0ab432bb-e2cc-42ea-a72c-7afef7536b38} + Ringtoets.AssemblyTool.KernelWrapper.TestUtil + {888D4097-8BC2-4703-9FB1-8744C94D525E} Ringtoets.HydraRing.Calculation