Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/AssemblyToolCalculatorFactoryConfig.cs =================================================================== diff -u -r91504f4e376343882bb60ff7f4bb25caf715a89d -r9a23713e85e58ebe4c9003690990ad8155e08408 --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/AssemblyToolCalculatorFactoryConfig.cs (.../AssemblyToolCalculatorFactoryConfig.cs) (revision 91504f4e376343882bb60ff7f4bb25caf715a89d) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/AssemblyToolCalculatorFactoryConfig.cs (.../AssemblyToolCalculatorFactoryConfig.cs) (revision 9a23713e85e58ebe4c9003690990ad8155e08408) @@ -40,7 +40,7 @@ /// } /// /// - public class AssemblyToolCalculatorFactoryConfig + public class AssemblyToolCalculatorFactoryConfig : IDisposable { private readonly IAssemblyToolCalculatorFactory previousFactory; Index: Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupLimitsFactory.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupLimitsFactory.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupLimitsFactory.cs (revision 9a23713e85e58ebe4c9003690990ad8155e08408) @@ -0,0 +1,59 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Collections.Generic; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; +using Riskeer.Common.Data.Exceptions; + +namespace Riskeer.Common.Data.AssemblyTool +{ + /// + /// Factory for calculating the assembly tool group limits. + /// + public static class AssemblyToolGroupLimitsFactory + { + /// + /// Creates the failure mechanism section assembly group limits. + /// + /// The signaling norm to use in the calculation. + /// The lower limit norm to use in the calculation. + /// A collection of . + /// Thrown when an error occurred while creating the assembly group limits. + public static IEnumerable CreateFailureMechanismSectionAssemblyGroupLimits( + double signalingNorm, double lowerLimitNorm) + { + IAssemblyGroupLimitsCalculator calculator = AssemblyToolCalculatorFactory.Instance.CreateAssemblyGroupLimitsCalculatorCalculator( + AssemblyToolKernelFactory.Instance); + + try + { + return calculator.CalculateFailureMechanismSectionAssemblyGroupLimits(signalingNorm, lowerLimitNorm); + } + catch (AssemblyCategoriesCalculatorException e) + { + throw new AssemblyException(e.Message, e); + } + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupLimitsFactoryTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupLimitsFactoryTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupLimitsFactoryTest.cs (revision 9a23713e85e58ebe4c9003690990ad8155e08408) @@ -0,0 +1,116 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Linq; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Categories; +using Riskeer.Common.Data.AssemblyTool; +using Riskeer.Common.Data.Exceptions; + +namespace Riskeer.Common.Data.Test.AssemblyTool +{ + [TestFixture] + public class AssemblyToolGroupLimitsFactoryTest + { + [Test] + public void CreateAssessmentSectionAssemblyCategories_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerLimitNorm = random.NextDouble(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupLimitsCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupLimitsCalculator; + + // Call + AssemblyToolGroupLimitsFactory.CreateFailureMechanismSectionAssemblyGroupLimits(signalingNorm, lowerLimitNorm); + + // Assert + Assert.AreEqual(signalingNorm, calculator.SignalingNorm); + Assert.AreEqual(lowerLimitNorm, calculator.LowerLimitNorm); + } + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_CalculatorRan_ReturnsOutput() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerLimitNorm = random.NextDouble(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupLimitsCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupLimitsCalculator; + + // Call + FailureMechanismSectionAssemblyGroupLimits[] output = + AssemblyToolGroupLimitsFactory.CreateFailureMechanismSectionAssemblyGroupLimits(signalingNorm, lowerLimitNorm) + .ToArray(); + + // Assert + FailureMechanismSectionAssemblyGroupLimits[] calculatorOutput = calculator.FailureMechanismSectionAssemblyGroupLimitsOutput.ToArray(); + + int expectedNrOfOutputs = calculatorOutput.Length; + Assert.AreEqual(expectedNrOfOutputs, output.Length); + for (var i = 0; i < expectedNrOfOutputs; i++) + { + FailureMechanismSectionAssemblyGroupLimits expectedOutput = calculatorOutput[i]; + FailureMechanismSectionAssemblyGroupLimits actualOutput = calculatorOutput[i]; + + Assert.AreEqual(expectedOutput.Group, actualOutput.Group); + Assert.AreEqual(expectedOutput.LowerBoundary, actualOutput.LowerBoundary); + Assert.AreEqual(expectedOutput.UpperBoundary, actualOutput.UpperBoundary); + } + } + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupLimitsCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupLimitsCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + void Call() => AssemblyToolGroupLimitsFactory.CreateFailureMechanismSectionAssemblyGroupLimits(0, 0); + + // Assert + var exception = Assert.Throws(Call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + } +} \ No newline at end of file