Index: Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs
===================================================================
diff -u -rec2c838182ed237b3abd753347a861857129331b -r252c1d1ac3a5a32b2f78bc0c577f3cf62d60b278
--- Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision ec2c838182ed237b3abd753347a861857129331b)
+++ Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision 252c1d1ac3a5a32b2f78bc0c577f3cf62d60b278)
@@ -1,16 +1,44 @@
-using Riskeer.AssemblyTool.Data;
+using System;
+using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Data.AssemblyTool;
using Riskeer.Common.Data.AssessmentSection;
using Riskeer.Common.Data.FailureMechanism;
namespace Riskeer.Integration.Data.StandAlone.AssemblyFactories
{
+ ///
+ /// Factory for assembling assembly results for a stand alone failure mechanism.
+ ///
public static class StandAloneFailureMechanismAssemblyFactory
{
+ ///
+ /// Assembles the section based on the input arguments.
+ ///
+ /// The section result to assemble.
+ /// The failure mechanism the section result belongs to.
+ /// The the section belongs to.
+ /// A .
+ /// Thrown when any argument is null.
+ /// Thrown when the section could not be assembled.
public static FailureMechanismSectionAssemblyResult AssembleSection(NonAdoptableWithProfileProbabilityFailureMechanismSectionResult sectionResult,
IHasGeneralInput failureMechanism,
IAssessmentSection assessmentSection)
{
+ if (sectionResult == null)
+ {
+ throw new ArgumentNullException(nameof(sectionResult));
+ }
+
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection);
}
}
Index: Riskeer/Integration/test/Riskeer.Integration.Data.Test/Assembly/StandAloneFailureMechanismAssemblyFactoryTest.cs
===================================================================
diff -u
--- Riskeer/Integration/test/Riskeer.Integration.Data.Test/Assembly/StandAloneFailureMechanismAssemblyFactoryTest.cs (revision 0)
+++ Riskeer/Integration/test/Riskeer.Integration.Data.Test/Assembly/StandAloneFailureMechanismAssemblyFactoryTest.cs (revision 252c1d1ac3a5a32b2f78bc0c577f3cf62d60b278)
@@ -0,0 +1,196 @@
+// 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 Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.AssemblyTool.Data;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators;
+using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly;
+using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Data.Contribution;
+using Riskeer.Common.Data.Exceptions;
+using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Common.Primitives;
+using Riskeer.Integration.Data.StandAlone.AssemblyFactories;
+
+namespace Riskeer.Integration.Data.Test.Assembly
+{
+ [TestFixture]
+ public class StandAloneFailureMechanismAssemblyFactoryTest
+ {
+ [Test]
+ public void AssembleSection_SectionResultNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var failureMechanism = new TestFailureMechanism();
+
+ // Call
+ void Call() => StandAloneFailureMechanismAssemblyFactory.AssembleSection(null, failureMechanism, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("sectionResult", exception.ParamName);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleSection_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);
+
+ // Call
+ void Call() => StandAloneFailureMechanismAssemblyFactory.AssembleSection(sectionResult, null, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleSection_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);
+
+ var failureMechanism = new TestFailureMechanism();
+
+ // Call
+ void Call() => StandAloneFailureMechanismAssemblyFactory.AssembleSection(sectionResult, failureMechanism, null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleSection_WithInput_SetsInputOnCalculator()
+ {
+ // Setup
+ var random = new Random(21);
+
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section)
+ {
+ IsRelevant = random.NextBoolean(),
+ InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.Manual,
+ ManualInitialFailureMechanismResultSectionProbability = random.NextDouble(),
+ FurtherAnalysisType = random.NextEnumValue(),
+ RefinedSectionProbability = random.NextDouble()
+ };
+
+ var failureMechanism = new TestFailureMechanism();
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+
+ // Call
+ StandAloneFailureMechanismAssemblyFactory.AssembleSection(sectionResult, failureMechanism, assessmentSection);
+
+ // Assert
+ FailureMechanismSectionAssemblyInput calculatorInput = calculator.FailureMechanismSectionAssemblyInput;
+ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
+ Assert.AreEqual(failureMechanismContribution.SignalingNorm, calculatorInput.SignalingNorm);
+ Assert.AreEqual(failureMechanismContribution.LowerLimitNorm, calculatorInput.LowerLimitNorm);
+
+ Assert.AreEqual(sectionResult.IsRelevant, calculatorInput.IsRelevant);
+ Assert.IsTrue(calculatorInput.HasProbabilitySpecified);
+
+ Assert.AreEqual(sectionResult.ManualInitialFailureMechanismResultSectionProbability, calculatorInput.InitialSectionProbability);
+ Assert.AreEqual(sectionResult.FurtherAnalysisType, calculatorInput.FurtherAnalysisType);
+ Assert.AreEqual(sectionResult.RefinedSectionProbability, calculatorInput.RefinedSectionProbability);
+ }
+ }
+
+ [Test]
+ public void AssembleSection_CalculatorRan_ReturnsExpectedOutput()
+ {
+ // Setup
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);
+
+ var failureMechanism = new TestFailureMechanism();
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+
+ // Call
+ FailureMechanismSectionAssemblyResult result = StandAloneFailureMechanismAssemblyFactory.AssembleSection(
+ sectionResult, failureMechanism, assessmentSection);
+
+ // Assert
+ Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, result);
+ }
+ }
+
+ [Test]
+ public void AssembleSection_CalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+ var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);
+
+ var failureMechanism = new TestFailureMechanism();
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ void Call() => StandAloneFailureMechanismAssemblyFactory.AssembleSection(
+ sectionResult, failureMechanism, assessmentSection);
+
+ // 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