Fisheye: Tag 134f43abf0f321d818ef0a02fa4b1f8d3fca068d refers to a dead (removed) revision in file `Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/PipingStructureFailureMechanismAssemblyFactory.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs =================================================================== diff -u -reca9022fde719d5d998065e7801e17194a51f93b -rc24134e3e4b9b06ec693eebf36b09b3e3a5a5177 --- Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision eca9022fde719d5d998065e7801e17194a51f93b) +++ Riskeer/Integration/src/Riskeer.Integration.Data/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactory.cs (.../StandAloneFailureMechanismAssemblyFactory.cs) (revision c24134e3e4b9b06ec693eebf36b09b3e3a5a5177) @@ -1,4 +1,25 @@ -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; @@ -46,8 +67,18 @@ return FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, failureMechanism.GeneralInput.ApplyLengthEffectInSection); } + /// + /// Assembles the failure mechanism based on its input arguments. + /// + /// The failure mechanism to assemble. + /// The the + /// belongs to. + /// A representing the assembly result. + /// The type of failure mechanism to assemble. + /// Thrown when any argument is null. + /// Thrown when the failure mechanism cannot be assembled. public static double AssembleFailureMechanism(TFailureMechanism failureMechanism, - AssessmentSection assessmentSection) + IAssessmentSection assessmentSection) where TFailureMechanism : IHasGeneralInput, IHasSectionResults { if (failureMechanism == null) Fisheye: Tag c24134e3e4b9b06ec693eebf36b09b3e3a5a5177 refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Data.Test/Assembly/StandAloneFailureMechanismAssemblyFactoryTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 134f43abf0f321d818ef0a02fa4b1f8d3fca068d refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Data.Test/StandAlone/AssemblyFactories/PipingStructureFailureMechanismAssemblyFactoryTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/test/Riskeer.Integration.Data.Test/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactoryTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Data.Test/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactoryTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Data.Test/StandAlone/AssemblyFactories/StandAloneFailureMechanismAssemblyFactoryTest.cs (revision c24134e3e4b9b06ec693eebf36b09b3e3a5a5177) @@ -0,0 +1,364 @@ +// 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 Core.Common.Base; +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.Calculation; +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; +using Riskeer.Integration.Data.StandAlone.AssemblyFactories; + +namespace Riskeer.Integration.Data.Test.StandAlone.AssemblyFactories +{ + [TestFixture] + public class StandAloneFailureMechanismAssemblyFactoryTest + { + private class TestFailureMechanism : FailureMechanismBase, + IHasSectionResults, + IHasGeneralInput + { + private readonly ObservableList sectionResults; + + public TestFailureMechanism() : base("Test", "Code", 1) + { + sectionResults = new ObservableList(); + GeneralInput = new GeneralInput(); + } + + public override IEnumerable Calculations { get; } + public IObservableEnumerable SectionResultsOld { get; } + + public IObservableEnumerable SectionResults => sectionResults; + + public GeneralInput GeneralInput { get; } + + protected override void AddSectionDependentData(FailureMechanismSection section) + { + base.AddSectionDependentData(section); + sectionResults.Add(new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section)); + } + } + + #region AssembleSection + + [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); + } + } + + #endregion + + #region AssembleFailureMechanism + + [Test] + public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => StandAloneFailureMechanismAssemblyFactory.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 TestFailureMechanism(); + + // Call + void Call() => StandAloneFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new TestFailureMechanism + { + 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 + StandAloneFailureMechanismAssemblyFactory.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 TestFailureMechanism + { + 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 = StandAloneFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(assemblyOutput, result); + } + } + + [Test] + public void AssembleFailureMechanism_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new TestFailureMechanism + { + 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() => StandAloneFailureMechanismAssemblyFactory.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