Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSectionAssemblyFactory.cs
===================================================================
diff -u
--- Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSectionAssemblyFactory.cs (revision 0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSectionAssemblyFactory.cs (revision f15874e4f7121382aa524339b7fc37eadd92d7aa)
@@ -0,0 +1,88 @@
+// 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 Ringtoets.AssemblyTool.Data;
+using Ringtoets.AssemblyTool.KernelWrapper.Calculators;
+using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Ringtoets.AssemblyTool.KernelWrapper.Kernels;
+using Ringtoets.ClosingStructures.Data;
+using Ringtoets.Common.Data.Contribution;
+using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.GrassCoverErosionInwards.Data;
+using Ringtoets.HeightStructures.Data;
+using Ringtoets.MacroStabilityInwards.Data;
+using Ringtoets.Piping.Data;
+using Ringtoets.StabilityPointStructures.Data;
+
+namespace Ringtoets.Integration.Data
+{
+ ///
+ /// Factory for assembling the assembly results for an assessment section.
+ ///
+ public static class AssessmentSectionAssemblyFactory
+ {
+ ///
+ /// Assembles the results of the assessment section based on the failure mechanisms with a probability.
+ ///
+ /// The assessment section which contains the failure mechanisms to assemble for.
+ /// A .
+ /// Thrown when is null.
+ /// Thrown when cannot be created.
+ public static AssessmentSectionAssembly AssembleFailureMechanismsWithProbability(AssessmentSection assessmentSection)
+ {
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ try
+ {
+ IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance;
+ IAssessmentSectionAssemblyCalculator calculator =
+ calculatorFactory.CreateAssessmentSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance);
+
+ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
+ return calculator.AssembleFailureMechanisms(GetFailureMechanismWithProbabilityAssemblyResults(assessmentSection),
+ failureMechanismContribution.SignalingNorm,
+ failureMechanismContribution.LowerLimitNorm);
+ }
+ catch (AssessmentSectionAssemblyCalculatorException e)
+ {
+ throw new AssemblyException(e.Message, e);
+ }
+ }
+
+ private static IEnumerable GetFailureMechanismWithProbabilityAssemblyResults(AssessmentSection assessmentSection)
+ {
+ return new[]
+ {
+ GrassCoverErosionInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.GrassCoverErosionInwards, assessmentSection),
+ HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.HeightStructures, assessmentSection),
+ ClosingStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.ClosingStructures, assessmentSection),
+ StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.StabilityPointStructures, assessmentSection),
+ PipingFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.Piping, assessmentSection),
+ MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(assessmentSection.MacroStabilityInwards, assessmentSection)
+ };
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/Ringtoets.Integration.Data.csproj
===================================================================
diff -u -rbbbfacd9e38cf43c98dba73e39694850fb932a66 -rf15874e4f7121382aa524339b7fc37eadd92d7aa
--- Ringtoets/Integration/src/Ringtoets.Integration.Data/Ringtoets.Integration.Data.csproj (.../Ringtoets.Integration.Data.csproj) (revision bbbfacd9e38cf43c98dba73e39694850fb932a66)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Data/Ringtoets.Integration.Data.csproj (.../Ringtoets.Integration.Data.csproj) (revision f15874e4f7121382aa524339b7fc37eadd92d7aa)
@@ -12,6 +12,7 @@
+
Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionAssemblyFactoryTest.cs
===================================================================
diff -u
--- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionAssemblyFactoryTest.cs (revision 0)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionAssemblyFactoryTest.cs (revision f15874e4f7121382aa524339b7fc37eadd92d7aa)
@@ -0,0 +1,139 @@
+// 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.Linq;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.AssemblyTool.Data;
+using Ringtoets.AssemblyTool.KernelWrapper.Calculators;
+using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
+using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.Common.Data.FailureMechanism;
+
+namespace Ringtoets.Integration.Data.Test
+{
+ [TestFixture]
+ public class AssessmentSectionAssemblyFactoryTest
+ {
+ [Test]
+ public void AssemblyFailureMechanismsWithProbability_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssessmentSectionAssemblyFactory.AssembleFailureMechanismsWithProbability(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_WithAssessmentSection_SetsInputOnCalculator()
+ {
+ // Setup
+ var random = new Random(21);
+ AssessmentSection assessmentSection = CreateAssessmentSection();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+
+ AssessmentSectionAssemblyCalculatorStub assessmentSectionAssemblyCalculator = calculatorfactory.LastCreatedAssessmentSectionAssemblyCalculator;
+
+ // Call
+ AssessmentSectionAssemblyFactory.AssembleFailureMechanismsWithProbability(assessmentSection);
+
+ // Assert
+ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
+ Assert.AreEqual(failureMechanismContribution.LowerLimitNorm, assessmentSectionAssemblyCalculator.LowerLimitNormInput);
+ Assert.AreEqual(failureMechanismContribution.SignalingNorm, assessmentSectionAssemblyCalculator.SignalingNormInput);
+
+ IEnumerable expectedFailureMechanisms = assessmentSection.GetFailureMechanisms().Where(fm => fm.Group == 1 || fm.Group == 2);
+
+ IEnumerable failureMechanismAssemblyInput = assessmentSectionAssemblyCalculator.FailureMechanismAssemblyInput;
+ Assert.AreEqual(expectedFailureMechanisms.Count(), failureMechanismAssemblyInput.Count());
+ foreach (FailureMechanismAssembly failureMechanismAssembly in failureMechanismAssemblyInput)
+ {
+ FailureMechanismAssembly expectedFailureMechanismAssembly = failureMechanismAssemblyCalculator.FailureMechanismAssemblyOutput;
+ Assert.AreEqual(expectedFailureMechanismAssembly.Group, failureMechanismAssembly.Group);
+ Assert.AreEqual(expectedFailureMechanismAssembly.Probability, failureMechanismAssembly.Probability);
+ }
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_AssemblyRan_ReturnsOutput()
+ {
+ // Setup
+ var random = new Random(21);
+ AssessmentSection assessmentSection = CreateAssessmentSection();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ AssessmentSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedAssessmentSectionAssemblyCalculator;
+ calculator.AssessmentSectionAssemblyOutput = new AssessmentSectionAssembly(random.NextDouble(),
+ random.NextEnumValue());
+
+ // Call
+ AssessmentSectionAssembly output = AssessmentSectionAssemblyFactory.AssembleFailureMechanismsWithProbability(assessmentSection);
+
+ // Assert
+ Assert.AreSame(calculator.AssessmentSectionAssemblyOutput, output);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_CalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ AssessmentSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedAssessmentSectionAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ TestDelegate call = () => AssessmentSectionAssemblyFactory.AssembleFailureMechanismsWithProbability(CreateAssessmentSection());
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+ }
+
+ private static AssessmentSection CreateAssessmentSection()
+ {
+ var random = new Random(21);
+ return new AssessmentSection(random.NextEnumValue());
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj
===================================================================
diff -u -rbbbfacd9e38cf43c98dba73e39694850fb932a66 -rf15874e4f7121382aa524339b7fc37eadd92d7aa
--- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj (.../Ringtoets.Integration.Data.Test.csproj) (revision bbbfacd9e38cf43c98dba73e39694850fb932a66)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj (.../Ringtoets.Integration.Data.Test.csproj) (revision f15874e4f7121382aa524339b7fc37eadd92d7aa)
@@ -18,6 +18,7 @@
+