Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismAssemblyFactory.cs =================================================================== diff -u -r9fa3b8b88015dfae67c87dc4d03c418995f0356f -r6139e3e65d0ed201012811a1b45ebd11d7587921 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismAssemblyFactory.cs (.../ClosingStructuresFailureMechanismAssemblyFactory.cs) (revision 9fa3b8b88015dfae67c87dc4d03c418995f0356f) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismAssemblyFactory.cs (.../ClosingStructuresFailureMechanismAssemblyFactory.cs) (revision 6139e3e65d0ed201012811a1b45ebd11d7587921) @@ -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(ClosingStructuresFailureMechanismSectionResult failureMechanismSectionResult, + ClosingStructuresFailureMechanism 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(ClosingStructuresFailureMechanism failureMechanism, - IAssessmentSection assessmentSection, - AssemblyCategoriesInput assemblyCategoriesInput) + private static FailureMechanismSectionAssembly GetSectionAssembly(ClosingStructuresFailureMechanismSectionResult failureMechanismSectionResult, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) { - var sectionAssemblies = new List(); - - foreach (ClosingStructuresFailureMechanismSectionResult 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/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismAssemblyFactoryTest.cs =================================================================== diff -u -r9fa3b8b88015dfae67c87dc4d03c418995f0356f -r6139e3e65d0ed201012811a1b45ebd11d7587921 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismAssemblyFactoryTest.cs) (revision 9fa3b8b88015dfae67c87dc4d03c418995f0356f) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismAssemblyFactoryTest.cs (.../ClosingStructuresFailureMechanismAssemblyFactoryTest.cs) (revision 6139e3e65d0ed201012811a1b45ebd11d7587921) @@ -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 = () => ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + null, + new ClosingStructuresFailureMechanism(), + 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 = () => ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new ClosingStructuresFailureMechanismSectionResult(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 = () => ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new ClosingStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_SetsInputOnCalculator() + { + // Setup + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + 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 + ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = ClosingStructuresFailureMechanismAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = ClosingStructuresFailureMechanismAssemblyFactory.AssembleDetailedAssessment( + sectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = ClosingStructuresFailureMechanismAssemblyFactory.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 ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + + 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 + ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.ManualAssemblyProbability, calculator.ManualAssemblyProbabilityInput); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + FailureMechanismSectionAssemblyCategoryGroup categoryGroup = ClosingStructuresFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedAssembly = ClosingStructuresFailureMechanismAssemblyFactory.AssembleCombinedAssessment( + sectionResult, + failureMechanism, + assessmentSection); + Assert.AreEqual(categoryGroup, expectedAssembly.Group); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + + 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 = ClosingStructuresFailureMechanismAssemblyFactory.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 ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = useManualAssembly + }; + var failureMechanism = new ClosingStructuresFailureMechanism(); + + 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 = () => ClosingStructuresFailureMechanismAssemblyFactory.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]