Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultAssemblyFactory.cs =================================================================== diff -u -r94153c6e76905f3080e2bbcdbe938ff5f8a714c4 -r7e7e78224b45e0c174ae881b9d6230a6caf980d2 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision 94153c6e76905f3080e2bbcdbe938ff5f8a714c4) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultAssemblyFactory.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactory.cs) (revision 7e7e78224b45e0c174ae881b9d6230a6caf980d2) @@ -20,10 +20,13 @@ // 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.AssemblyTool; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; namespace Ringtoets.HeightStructures.Data @@ -63,5 +66,56 @@ throw new AssemblyFactoryException(e.Message, e); } } + + /// + /// Assembles the detailed assessment result. + /// + /// The failure mechanism section result to + /// assemble the detailed assembly for. + /// The failure mechanism belonging to this calculation. + /// The belonging to this calculation. + /// A . + /// Thrown when any parameter is null. + /// Thrown when + /// cannot be assembled. + public static FailureMechanismSectionAssembly AssembleDetailedAssembly( + HeightStructuresFailureMechanismSectionResult failureMechanismSectionResult, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanismSectionResult == null) + { + throw new ArgumentNullException(nameof(failureMechanismSectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance; + IFailureMechanismSectionAssemblyCalculator calculator = calculatorFactory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + try + { + IEnumerable categories = AssemblyToolCategoriesFactory.CreateFailureMechanismSectionAssemblyCategories( + assessmentSection.FailureMechanismContribution.SignalingNorm, + assessmentSection.FailureMechanismContribution.LowerLimitNorm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N); + + return calculator.AssembleDetailedAssessment(failureMechanismSectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), + categories); + } + catch (FailureMechanismSectionAssemblyCalculatorException e) + { + throw new AssemblyFactoryException(e.Message, e); + } + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -r94153c6e76905f3080e2bbcdbe938ff5f8a714c4 -r7e7e78224b45e0c174ae881b9d6230a6caf980d2 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 94153c6e76905f3080e2bbcdbe938ff5f8a714c4) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 7e7e78224b45e0c174ae881b9d6230a6caf980d2) @@ -20,13 +20,17 @@ // All rights reserved. using System; +using System.Linq; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; 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; using Ringtoets.Common.Data.TestUtil; @@ -37,6 +41,8 @@ [TestFixture] public class HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest { + #region Simple Assessment + [Test] public void AssembleSimpleAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { @@ -117,5 +123,180 @@ Assert.AreEqual(innerException.Message, exception.Message); } } + + #endregion + + #region Detailed Assessment + + [Test] + public void AssembleDetailedAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + null, + new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleDetailedAssembly_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleDetailedAssembly_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new HeightStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleDetailedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), + calculator.DetailedAssessmentProbabilityInput); + Assert.IsNotNull(calculator.DetailedAssessmentCategoriesInput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleDetailedAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.DetailedAssessmentAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + } + } + + [Test] + public void AssembleDetailedAssembly_CalculatorThrowsExceptions_ThrowsAssemblyFactoryException() + { + // Setup + var random = new Random(21); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( + Enumerable.Empty(), + random.Next(0, 100), + random.NextRoundedDouble(0.06, 0.1), + random.NextRoundedDouble(0.00001, 0.05))); + mocks.ReplayAll(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + SimpleAssessmentResult = random.NextEnumValue() + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + new HeightStructuresFailureMechanism(), + 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