Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs
===================================================================
diff -u -rc810defe67c7219b58c6da0b0059f687bf4231ea -r80d36751940e21e14d24b16e6c6e62bcd6615fcd
--- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision c810defe67c7219b58c6da0b0059f687bf4231ea)
+++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision 80d36751940e21e14d24b16e6c6e62bcd6615fcd)
@@ -20,12 +20,14 @@
// 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.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.Common.Primitives;
namespace Ringtoets.ClosingStructures.Data
{
@@ -106,10 +108,7 @@
return calculator.AssembleDetailedAssessment(
failureMechanismSectionResult.DetailedAssessmentResult,
failureMechanismSectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection),
- new AssemblyCategoriesInput(failureMechanism.GeneralInput.N,
- failureMechanism.Contribution,
- assessmentSection.FailureMechanismContribution.SignalingNorm,
- assessmentSection.FailureMechanismContribution.LowerLimitNorm));
+ CreateAssemblyCategoriesInput(failureMechanism, assessmentSection));
}
catch (FailureMechanismSectionAssemblyCalculatorException e)
{
@@ -157,10 +156,7 @@
return calculator.AssembleTailorMadeAssessment(
failureMechanismSectionResult.TailorMadeAssessmentResult,
failureMechanismSectionResult.TailorMadeAssessmentProbability,
- new AssemblyCategoriesInput(failureMechanism.GeneralInput.N,
- failureMechanism.Contribution,
- assessmentSection.FailureMechanismContribution.SignalingNorm,
- assessmentSection.FailureMechanismContribution.LowerLimitNorm));
+ CreateAssemblyCategoriesInput(failureMechanism, assessmentSection));
}
catch (FailureMechanismSectionAssemblyCalculatorException e)
{
@@ -216,5 +212,84 @@
throw new AssemblyException(e.Message, e);
}
}
+
+ ///
+ /// Assembles the failure mechanism assembly.
+ ///
+ /// The failure mechanism section results to
+ /// get the assembly for.
+ /// The failure mechanism to assemble for.
+ /// The the failure mechanism belongs to.
+ /// Indicator whether the manual assembly should be used in the assembly.
+ /// A .
+ /// Thrown when any parameter is null.
+ /// Thrown when the
+ /// could not be created.
+ public static FailureMechanismAssembly AssembleFailureMechanism(
+ IEnumerable failureMechanismSectionResults,
+ ClosingStructuresFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection,
+ bool considerManualAssembly = true)
+ {
+ if (failureMechanismSectionResults == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanismSectionResults));
+ }
+
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance;
+ IFailureMechanismSectionAssemblyCalculator sectionCalculator =
+ calculatorFactory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance);
+
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput(failureMechanism, assessmentSection);
+ var sectionAssemblies = new List();
+
+ try
+ {
+ foreach (ClosingStructuresFailureMechanismSectionResult sectionResult in failureMechanismSectionResults)
+ {
+ if (sectionResult.UseManualAssemblyProbability && considerManualAssembly)
+ {
+ sectionAssemblies.Add(sectionCalculator.AssembleDetailedAssessment(
+ DetailedAssessmentProbabilityOnlyResultType.Probability,
+ sectionResult.ManualAssemblyProbability,
+ assemblyCategoriesInput));
+ }
+ else
+ {
+ sectionAssemblies.Add(AssembleCombinedAssessment(sectionResult,
+ failureMechanism,
+ assessmentSection));
+ }
+ }
+
+ IFailureMechanismAssemblyCalculator calculator =
+ calculatorFactory.CreateFailureMechanismAssemblyCalculator(AssemblyToolKernelFactory.Instance);
+
+ return calculator.AssembleFailureMechanism(sectionAssemblies, assemblyCategoriesInput);
+ }
+ catch (Exception e) when (e is FailureMechanismAssemblyCalculatorException || e is FailureMechanismSectionAssemblyCalculatorException)
+ {
+ throw new AssemblyException(e.Message, e);
+ }
+ }
+
+ private static AssemblyCategoriesInput CreateAssemblyCategoriesInput(ClosingStructuresFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ return new AssemblyCategoriesInput(failureMechanism.GeneralInput.N,
+ failureMechanism.Contribution,
+ assessmentSection.FailureMechanismContribution.SignalingNorm,
+ assessmentSection.FailureMechanismContribution.LowerLimitNorm);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs
===================================================================
diff -u -r6d4dddb1327f3ecb92064e62d18d89bfcd0daa11 -r80d36751940e21e14d24b16e6c6e62bcd6615fcd
--- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 6d4dddb1327f3ecb92064e62d18d89bfcd0daa11)
+++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 80d36751940e21e14d24b16e6c6e62bcd6615fcd)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Linq;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -608,5 +609,273 @@
}
#endregion
+
+ #region Failure Mechanism Assembly
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismSectionResultsNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ null,
+ new ClosingStructuresFailureMechanism(),
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("failureMechanismSectionResults", exception.ParamName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ Enumerable.Empty(),
+ null,
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ Enumerable.Empty(),
+ new ClosingStructuresFailureMechanism(),
+ null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithoutManualInput_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var sectionResults = new[]
+ {
+ new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ };
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ sectionResults,
+ failureMechanism,
+ assessmentSection);
+
+ // Assert
+ FailureMechanismSectionAssembly expectedAssembly = ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment(
+ sectionResults.Single(),
+ failureMechanism,
+ assessmentSection);
+ AssemblyToolTestHelper.AssertAreEqual(expectedAssembly, calculator.FailureMechanismSectionAssemblies.Single());
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithManualInputConsiderManualAssemblyTrue_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var sectionResults = new[]
+ {
+ new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ {
+ UseManualAssemblyProbability = true,
+ ManualAssemblyProbability = new Random(39).NextDouble()
+ }
+ };
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ sectionResults,
+ failureMechanism,
+ assessmentSection);
+
+ // Assert
+ FailureMechanismSectionAssembly expectedAssembly = ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssessment(
+ sectionResults.Single(),
+ failureMechanism,
+ assessmentSection);
+ AssemblyToolTestHelper.AssertAreEqual(expectedAssembly, calculator.FailureMechanismSectionAssemblies.Single());
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithManualInputConsiderManualAssemblyFalse_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ var sectionResults = new[]
+ {
+ new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ {
+ UseManualAssemblyProbability = true,
+ ManualAssemblyProbability = new Random(39).NextDouble()
+ }
+ };
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ sectionResults,
+ failureMechanism,
+ assessmentSection,
+ false);
+
+ // Assert
+ FailureMechanismSectionAssembly expectedAssembly = ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment(
+ sectionResults.Single(),
+ failureMechanism,
+ assessmentSection);
+ AssemblyToolTestHelper.AssertAreEqual(expectedAssembly, calculator.FailureMechanismSectionAssemblies.Single());
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_AssemblyRan_ReturnsOutput()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ FailureMechanismAssembly actualOutput =
+ ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ Enumerable.Empty(),
+ failureMechanism,
+ assessmentSection);
+
+ // Assert
+ Assert.AreSame(calculator.FailureMechanismAssemblyOutput, actualOutput);
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismCalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ Enumerable.Empty(),
+ failureMechanism,
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismSectionCalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var mocks = new MockRepository();
+ IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
+ mocks.ReplayAll();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculateCombinedAssembly = true;
+
+ // Call
+ TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultAssemblyFactory.AssembleFailureMechanism(
+ new[]
+ {
+ new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ },
+ failureMechanism,
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ mocks.VerifyAll();
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.cs
===================================================================
diff -u -r4e9e1bc4a1133138ee51c3a62a885010832f6d7f -r80d36751940e21e14d24b16e6c6e62bcd6615fcd
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.cs (.../MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 4e9e1bc4a1133138ee51c3a62a885010832f6d7f)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.cs (.../MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 80d36751940e21e14d24b16e6c6e62bcd6615fcd)
@@ -238,7 +238,7 @@
/// The failure mechanism section results to
/// get the assembly for.
/// The calculation scenarios belonging to this failure mechanism.
- /// The failure mechanism this to assemble for.
+ /// The failure mechanism to assemble for.
/// The the failure mechanism belongs to.
/// Indicator whether the manual assembly should be used in the assembly.
/// A .
@@ -305,14 +305,10 @@
return calculator.AssembleFailureMechanism(sectionAssemblies, assemblyCategoriesInput);
}
- catch (FailureMechanismSectionAssemblyCalculatorException e)
+ catch (Exception e) when (e is FailureMechanismAssemblyCalculatorException || e is FailureMechanismSectionAssemblyCalculatorException)
{
throw new AssemblyException(e.Message, e);
}
- catch (FailureMechanismAssemblyCalculatorException e)
- {
- throw new AssemblyException(e.Message, e);
- }
}
private static AssemblyCategoriesInput CreateAssemblyCategoriesInput(MacroStabilityInwardsFailureMechanism failureMechanism,
Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs
===================================================================
diff -u -r4e9e1bc4a1133138ee51c3a62a885010832f6d7f -r80d36751940e21e14d24b16e6c6e62bcd6615fcd
--- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs (.../PipingFailureMechanismSectionResultAssemblyFactory.cs) (revision 4e9e1bc4a1133138ee51c3a62a885010832f6d7f)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs (.../PipingFailureMechanismSectionResultAssemblyFactory.cs) (revision 80d36751940e21e14d24b16e6c6e62bcd6615fcd)
@@ -238,7 +238,7 @@
/// The failure mechanism section results to
/// get the assembly for.
/// The calculation scenarios belonging to this failure mechanism.
- /// The failure mechanism this to assemble for.
+ /// The failure mechanism to assemble for.
/// The the failure mechanism belongs to.
/// Indicator whether the manual assembly should be used in the assembly.
/// A .
@@ -305,14 +305,10 @@
return calculator.AssembleFailureMechanism(sectionAssemblies, assemblyCategoriesInput);
}
- catch (FailureMechanismSectionAssemblyCalculatorException e)
+ catch (Exception e) when (e is FailureMechanismAssemblyCalculatorException || e is FailureMechanismSectionAssemblyCalculatorException)
{
throw new AssemblyException(e.Message, e);
}
- catch (FailureMechanismAssemblyCalculatorException e)
- {
- throw new AssemblyException(e.Message, e);
- }
}
private static AssemblyCategoriesInput CreateAssemblyCategoriesInput(PipingFailureMechanism failureMechanism,