Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismAssemblyFactory.cs =================================================================== diff -u -r06800c4b5c53dd8a385a9f15ce44e9c4038a3726 -r7d14a67ab314b9b782bbaefe3bcdd6459fa1c5e3 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismAssemblyFactory.cs (.../StabilityPointStructuresFailureMechanismAssemblyFactory.cs) (revision 06800c4b5c53dd8a385a9f15ce44e9c4038a3726) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismAssemblyFactory.cs (.../StabilityPointStructuresFailureMechanismAssemblyFactory.cs) (revision 7d14a67ab314b9b782bbaefe3bcdd6459fa1c5e3) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; @@ -214,6 +215,38 @@ } /// + /// Gets the assembly category group of the given . + /// + /// The failure mechanism section result to get the assembly category group for. + /// The failure mechanism this section belongs to. + /// The this section belongs to. + /// A . + /// Thrown when any parameter is null. + /// Thrown when the + /// could not be created. + public static FailureMechanismSectionAssemblyCategoryGroup GetSectionAssemblyCategoryGroup(StabilityPointStructuresFailureMechanismSectionResult failureMechanismSectionResult, + StabilityPointStructuresFailureMechanism 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)); + } + + return GetSectionAssembly(failureMechanismSectionResult, failureMechanism, assessmentSection).Group; + } + + /// /// Assembles the failure mechanism assembly. /// /// The failure mechanism to assemble for. @@ -243,9 +276,9 @@ IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance; AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput(failureMechanism, assessmentSection); - IEnumerable sectionAssemblies = AssembleSections(failureMechanism, - assessmentSection, - assemblyCategoriesInput); + IEnumerable sectionAssemblies = failureMechanism.SectionResults + .Select(sr => GetSectionAssembly(sr, failureMechanism, assessmentSection)) + .ToArray(); try { @@ -261,38 +294,32 @@ } /// - /// Assembles the combined assembly for all sections in the . + /// Gets the assembly of the given . /// + /// The failure mechanism section result to get the assembly for. /// The failure mechanism to assemble for. /// The the failure mechanism belongs to. - /// The input parameters used to determine the assembly categories. /// A collection of all section assembly results. /// Thrown when a /// could not be created. - private static IEnumerable AssembleSections(StabilityPointStructuresFailureMechanism failureMechanism, - IAssessmentSection assessmentSection, - AssemblyCategoriesInput assemblyCategoriesInput) + private static FailureMechanismSectionAssembly GetSectionAssembly(StabilityPointStructuresFailureMechanismSectionResult failureMechanismSectionResult, + StabilityPointStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) { - var sectionAssemblies = new List(); - - foreach (StabilityPointStructuresFailureMechanismSectionResult sectionResult in failureMechanism.SectionResults) + FailureMechanismSectionAssembly sectionAssembly; + if (failureMechanismSectionResult.UseManualAssemblyProbability) { - FailureMechanismSectionAssembly sectionAssembly; - if (sectionResult.UseManualAssemblyProbability) - { - sectionAssembly = AssembleManualAssessment(sectionResult, assemblyCategoriesInput); - } - else - { - sectionAssembly = AssembleCombinedAssessment(sectionResult, - failureMechanism, - assessmentSection); - } - - sectionAssemblies.Add(sectionAssembly); + sectionAssembly = AssembleManualAssessment(failureMechanismSectionResult, + CreateAssemblyCategoriesInput(failureMechanism, assessmentSection)); } + else + { + sectionAssembly = AssembleCombinedAssessment(failureMechanismSectionResult, + failureMechanism, + assessmentSection); + } - return sectionAssemblies; + return sectionAssembly; } /// Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismAssemblyFactoryTest.cs =================================================================== diff -u -r06800c4b5c53dd8a385a9f15ce44e9c4038a3726 -r7d14a67ab314b9b782bbaefe3bcdd6459fa1c5e3 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismAssemblyFactoryTest.cs (.../StabilityPointStructuresFailureMechanismAssemblyFactoryTest.cs) (revision 06800c4b5c53dd8a385a9f15ce44e9c4038a3726) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismAssemblyFactoryTest.cs (.../StabilityPointStructuresFailureMechanismAssemblyFactoryTest.cs) (revision 7d14a67ab314b9b782bbaefe3bcdd6459fa1c5e3) @@ -611,6 +611,247 @@ #endregion + #region GetSectionAssemblyCategoryGroup + + [Test] + public void GetSectionAssemblyCategoryGroup_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + null, + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetSectionAssemblyCategoryGroup_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetSectionAssemblyCategoryGroup_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new StabilityPointStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_SetsInputOnCalculator() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleDetailedAssessment( + sectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( + sectionResult, + failureMechanism, + assessmentSection); + + AssemblyToolTestHelper.AssertAreEqual(expectedSimpleAssembly, calculator.CombinedSimpleAssemblyInput); + AssemblyToolTestHelper.AssertAreEqual(expectedDetailedAssembly, calculator.CombinedDetailedAssemblyInput); + AssemblyToolTestHelper.AssertAreEqual(expectedTailorMadeAssembly, calculator.CombinedTailorMadeAssemblyInput); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithManualInput_SetsInputOnCalculator() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.ManualAssemblyProbability, calculator.ManualAssemblyProbabilityInput); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + FailureMechanismSectionAssemblyCategoryGroup categoryGroup = StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedAssembly = StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleCombinedAssessment( + sectionResult, + failureMechanism, + assessmentSection); + Assert.AreEqual(categoryGroup, expectedAssembly.Group); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyCategoryGroup categoryGroup = StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedAssembly = calculator.AssembleManual( + sectionResult.ManualAssemblyProbability, + AssemblyCategoriesInputFactory.CreateAssemblyCategoriesInput(0.0, failureMechanism, assessmentSection)); + Assert.AreEqual(categoryGroup, expectedAssembly.Group); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GetSectionAssemblyCategoryGroup_CalculatorThrowsException_ThrowsAssemblyException(bool useManualAssembly) + { + // Setup + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = useManualAssembly + }; + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + if (useManualAssembly) + { + calculator.ThrowExceptionOnCalculate = true; + } + else + { + calculator.ThrowExceptionOnCalculateCombinedAssembly = true; + } + + // Call + TestDelegate call = () => StabilityPointStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + mocks.VerifyAll(); + } + } + + #endregion + #region Failure Mechanism Assembly [Test]