Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.cs
===================================================================
diff -u -rec2c838182ed237b3abd753347a861857129331b -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.cs (.../GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.cs) (revision ec2c838182ed237b3abd753347a861857129331b)
+++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.cs (.../GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -20,11 +20,14 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
+using System.Linq;
using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Data.AssemblyTool;
using Riskeer.Common.Data.AssessmentSection;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
namespace Riskeer.GrassCoverErosionOutwards.Data
{
@@ -63,5 +66,39 @@
return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection);
}
+
+ ///
+ /// Assembles the failure mechanism based on its input arguments.
+ ///
+ /// The to assemble.
+ /// The the
+ /// belongs to.
+ /// A representing the assembly result.
+ /// Thrown when any argument is null.
+ /// Thrown when the failure mechanism could not be assembled.
+ public static double AssembleFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ Func performAssemblyFunc = () =>
+ {
+ IEnumerable sectionAssemblyResults =
+ failureMechanism.SectionResults.Select(sr => AssembleSection(sr, failureMechanism, assessmentSection))
+ .ToArray();
+
+ return FailureMechanismAssemblyResultFactory.AssembleFailureMechanism(failureMechanism.GeneralInput.N,
+ sectionAssemblyResults);
+ };
+ return FailurePathAssemblyHelper.AssembleFailurePath(failureMechanism, performAssemblyFunc);
+ }
}
}
\ No newline at end of file
Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest.cs
===================================================================
diff -u -rab91e93965a76b4b765204f935c8160533516c45 -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest.cs (.../GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest.cs) (revision ab91e93965a76b4b765204f935c8160533516c45)
+++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Data.Test/GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest.cs (.../GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Linq;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -32,6 +33,7 @@
using Riskeer.Common.Data.Contribution;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
using Riskeer.Common.Data.TestUtil;
using Riskeer.Common.Primitives;
@@ -40,6 +42,8 @@
[TestFixture]
public class GrassCoverErosionOutwardsFailureMechanismAssemblyFactoryTest
{
+ #region AssembleSection
+
[Test]
public void AssembleSection_SectionResultNull_ThrowsArgumentNullException()
{
@@ -191,5 +195,140 @@
Assert.AreEqual(innerException.Message, exception.Message);
}
}
+
+ #endregion
+
+ #region AssembleFailureMechanism
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(null, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();
+
+ // Call
+ void Call() => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+ failureMechanism.SetSections(new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ }, "APath");
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+
+ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ double expectedN = failureMechanism.GeneralInput.N;
+ Assert.AreEqual(expectedN, failureMechanismAssemblyCalculator.FailureMechanismN);
+ Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorRan_ReturnsExpectedOutput()
+ {
+ // Setup
+ var random = new Random(21);
+ double assemblyOutput = random.NextDouble();
+
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.AssemblyResult = assemblyOutput;
+
+ // Call
+ double result = GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ Assert.AreEqual(assemblyOutput, result);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ void Call() => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs
===================================================================
diff -u -r252c1d1ac3a5a32b2f78bc0c577f3cf62d60b278 -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision 252c1d1ac3a5a32b2f78bc0c577f3cf62d60b278)
+++ Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -1,8 +1,12 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Data.AssemblyTool;
using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
namespace Riskeer.Integration.Data.StandAlone.AssemblyFactories
{
@@ -41,5 +45,30 @@
return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection);
}
+
+ public static double AssembleFailureMechanism(TFailureMechanism failureMechanism,
+ AssessmentSection assessmentSection)
+ where TFailureMechanism : IHasGeneralInput, IHasSectionResults
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ Func performAssemblyFunc = () =>
+ {
+ IEnumerable sectionAssemblyResults =
+ failureMechanism.SectionResults.Select(sr => AssembleSection(sr, failureMechanism, assessmentSection))
+ .ToArray();
+ return FailureMechanismAssemblyResultFactory.AssembleFailureMechanism(failureMechanism.GeneralInput.N, sectionAssemblyResults);
+ };
+
+ return FailurePathAssemblyHelper.AssembleFailurePath(failureMechanism, performAssemblyFunc);
+ }
}
}
\ No newline at end of file
Index: Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Data/StabilityStoneCoverFailureMechanismAssemblyFactory.cs
===================================================================
diff -u -rec2c838182ed237b3abd753347a861857129331b -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Data/StabilityStoneCoverFailureMechanismAssemblyFactory.cs (.../StabilityStoneCoverFailureMechanismAssemblyFactory.cs) (revision ec2c838182ed237b3abd753347a861857129331b)
+++ Riskeer/StabilityStoneCover/src/Riskeer.StabilityStoneCover.Data/StabilityStoneCoverFailureMechanismAssemblyFactory.cs (.../StabilityStoneCoverFailureMechanismAssemblyFactory.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -20,11 +20,14 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
+using System.Linq;
using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Data.AssemblyTool;
using Riskeer.Common.Data.AssessmentSection;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
namespace Riskeer.StabilityStoneCover.Data
{
@@ -63,5 +66,39 @@
return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection);
}
+
+ ///
+ /// Assembles the failure mechanism based on its input arguments.
+ ///
+ /// The to assemble.
+ /// The the
+ /// belongs to.
+ /// A representing the assembly result.
+ /// Thrown when any argument is null.
+ /// Thrown when the failure mechanism could not be assembled.
+ public static double AssembleFailureMechanism(StabilityStoneCoverFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ Func performAssemblyFunc = () =>
+ {
+ IEnumerable sectionAssemblyResults =
+ failureMechanism.SectionResults.Select(sr => AssembleSection(sr, failureMechanism, assessmentSection))
+ .ToArray();
+
+ return FailureMechanismAssemblyResultFactory.AssembleFailureMechanism(failureMechanism.GeneralInput.N,
+ sectionAssemblyResults);
+ };
+ return FailurePathAssemblyHelper.AssembleFailurePath(failureMechanism, performAssemblyFunc);
+ }
}
}
\ No newline at end of file
Index: Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Data.Test/StabilityStoneCoverFailureMechanismAssemblyFactoryTest.cs
===================================================================
diff -u -rab91e93965a76b4b765204f935c8160533516c45 -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Data.Test/StabilityStoneCoverFailureMechanismAssemblyFactoryTest.cs (.../StabilityStoneCoverFailureMechanismAssemblyFactoryTest.cs) (revision ab91e93965a76b4b765204f935c8160533516c45)
+++ Riskeer/StabilityStoneCover/test/Riskeer.StabilityStoneCover.Data.Test/StabilityStoneCoverFailureMechanismAssemblyFactoryTest.cs (.../StabilityStoneCoverFailureMechanismAssemblyFactoryTest.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Linq;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -32,6 +33,7 @@
using Riskeer.Common.Data.Contribution;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
using Riskeer.Common.Data.TestUtil;
using Riskeer.Common.Primitives;
@@ -40,6 +42,8 @@
[TestFixture]
public class StabilityStoneCoverFailureMechanismAssemblyFactoryTest
{
+ #region AssembleSection
+
[Test]
public void AssembleSection_SectionResultNull_ThrowsArgumentNullException()
{
@@ -191,5 +195,140 @@
Assert.AreEqual(innerException.Message, exception.Message);
}
}
+
+ #endregion
+
+ #region AssembleFailureMechanism
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(null, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var failureMechanism = new StabilityStoneCoverFailureMechanism();
+
+ // Call
+ void Call() => StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new StabilityStoneCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+ failureMechanism.SetSections(new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ }, "APath");
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+
+ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ double expectedN = failureMechanism.GeneralInput.N;
+ Assert.AreEqual(expectedN, failureMechanismAssemblyCalculator.FailureMechanismN);
+ Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorRan_ReturnsExpectedOutput()
+ {
+ // Setup
+ var random = new Random(21);
+ double assemblyOutput = random.NextDouble();
+
+ var failureMechanism = new StabilityStoneCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.AssemblyResult = assemblyOutput;
+
+ // Call
+ double result = StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ Assert.AreEqual(assemblyOutput, result);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ var failureMechanism = new StabilityStoneCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ void Call() => StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Data/WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.cs
===================================================================
diff -u -rec2c838182ed237b3abd753347a861857129331b -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Data/WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.cs (.../WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.cs) (revision ec2c838182ed237b3abd753347a861857129331b)
+++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Data/WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.cs (.../WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -1,9 +1,33 @@
-using System;
+// 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.Collections.Generic;
+using System.Linq;
using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Data.AssemblyTool;
using Riskeer.Common.Data.AssessmentSection;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
namespace Riskeer.WaveImpactAsphaltCover.Data
{
@@ -42,5 +66,39 @@
return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralWaveImpactAsphaltCoverInput.ApplyLengthEffectInSection);
}
+
+ ///
+ /// Assembles the failure mechanism based on its input arguments.
+ ///
+ /// The to assemble.
+ /// The the
+ /// belongs to.
+ /// A representing the assembly result.
+ /// Thrown when any argument is null.
+ /// Thrown when the failure mechanism could not be assembled.
+ public static double AssembleFailureMechanism(WaveImpactAsphaltCoverFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ Func performAssemblyFunc = () =>
+ {
+ IEnumerable sectionAssemblyResults =
+ failureMechanism.SectionResults.Select(sr => AssembleSection(sr, failureMechanism, assessmentSection))
+ .ToArray();
+
+ return FailureMechanismAssemblyResultFactory.AssembleFailureMechanism(failureMechanism.GeneralWaveImpactAsphaltCoverInput.GetN(assessmentSection.ReferenceLine.Length),
+ sectionAssemblyResults);
+ };
+ return FailurePathAssemblyHelper.AssembleFailurePath(failureMechanism, performAssemblyFunc);
+ }
}
}
\ No newline at end of file
Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Data.Test/WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest.cs
===================================================================
diff -u -rab91e93965a76b4b765204f935c8160533516c45 -reca9022fde719d5d998065e7801e17194a51f93b
--- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Data.Test/WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest.cs (.../WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest.cs) (revision ab91e93965a76b4b765204f935c8160533516c45)
+++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Data.Test/WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest.cs (.../WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Linq;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -32,6 +33,7 @@
using Riskeer.Common.Data.Contribution;
using Riskeer.Common.Data.Exceptions;
using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.FailurePath;
using Riskeer.Common.Data.TestUtil;
using Riskeer.Common.Primitives;
@@ -40,6 +42,8 @@
[TestFixture]
public class WaveImpactAsphaltCoverFailureMechanismAssemblyFactoryTest
{
+ #region AssembleSection
+
[Test]
public void AssembleSection_SectionResultNull_ThrowsArgumentNullException()
{
@@ -191,5 +195,140 @@
Assert.AreEqual(innerException.Message, exception.Message);
}
}
+
+ #endregion
+
+ #region AssembleFailureMechanism
+
+ [Test]
+ public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ void Call() => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(null, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
+
+ // Call
+ void Call() => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
+ {
+ // Setup
+ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+ failureMechanism.SetSections(new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ }, "APath");
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
+
+ FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+
+ // Call
+ WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ double expectedN = failureMechanism.GeneralWaveImpactAsphaltCoverInput.GetN(assessmentSection.ReferenceLine.Length);
+ Assert.AreEqual(expectedN, failureMechanismAssemblyCalculator.FailureMechanismN);
+ Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorRan_ReturnsExpectedOutput()
+ {
+ // Setup
+ var random = new Random(21);
+ double assemblyOutput = random.NextDouble();
+
+ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.AssemblyResult = assemblyOutput;
+
+ // Call
+ double result = WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ Assert.AreEqual(assemblyOutput, result);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanism_CalculatorThrowsException_ThrowsAssemblyException()
+ {
+ // Setup
+ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
+ {
+ AssemblyResult =
+ {
+ ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic
+ }
+ };
+
+ var assessmentSection = new AssessmentSectionStub();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+
+ // Call
+ void Call() => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file