Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismAssemblyFactory.cs =================================================================== diff -u -r06800c4b5c53dd8a385a9f15ce44e9c4038a3726 -r1ccc4cae6b203b1f7791833ab1ad0bcba0a9757f --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismAssemblyFactory.cs (.../MacroStabilityInwardsFailureMechanismAssemblyFactory.cs) (revision 06800c4b5c53dd8a385a9f15ce44e9c4038a3726) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismAssemblyFactory.cs (.../MacroStabilityInwardsFailureMechanismAssemblyFactory.cs) (revision 1ccc4cae6b203b1f7791833ab1ad0bcba0a9757f) @@ -234,6 +234,53 @@ } /// + /// 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(MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult, + MacroStabilityInwardsFailureMechanism 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)); + } + + FailureMechanismSectionAssembly sectionAssembly; + if (failureMechanismSectionResult.UseManualAssemblyProbability) + { + sectionAssembly = AssembleManualAssessment(failureMechanismSectionResult, + failureMechanism, + CreateAssemblyCategoriesInput(failureMechanism, assessmentSection)); + } + else + { + sectionAssembly = AssembleCombinedAssessment(failureMechanismSectionResult, + failureMechanism.Calculations.Cast(), + failureMechanism, + assessmentSection); + } + + return sectionAssembly.Group; + } + + /// /// Assembles the failure mechanism assembly. /// /// The failure mechanism to assemble for. Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismAssemblyFactoryTest.cs =================================================================== diff -u -r06800c4b5c53dd8a385a9f15ce44e9c4038a3726 -r1ccc4cae6b203b1f7791833ab1ad0bcba0a9757f --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismAssemblyFactoryTest.cs (.../MacroStabilityInwardsFailureMechanismAssemblyFactoryTest.cs) (revision 06800c4b5c53dd8a385a9f15ce44e9c4038a3726) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismAssemblyFactoryTest.cs (.../MacroStabilityInwardsFailureMechanismAssemblyFactoryTest.cs) (revision 1ccc4cae6b203b1f7791833ab1ad0bcba0a9757f) @@ -690,6 +690,249 @@ #endregion + #region GetSectionAssemblyCategoryGroup + + [Test] + public void GetSectionAssemblyCategoryGroup_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + null, + new MacroStabilityInwardsFailureMechanism(), + 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 = () => MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new MacroStabilityInwardsFailureMechanismSectionResult(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 = () => MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new MacroStabilityInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_SetsInputOnCalculator() + { + // Setup + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + 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 + MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.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 MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + 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 + MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.ManualAssemblyProbability, calculator.ManualAssemblyProbabilityInput); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithoutManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + FailureMechanismSectionAssemblyCategoryGroup categoryGroup = MacroStabilityInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection); + Assert.AreEqual(categoryGroup, expectedAssembly.Group); + mocks.VerifyAll(); + } + } + + [Test] + public void GetSectionAssemblyCategoryGroup_WithManualInput_ReturnsOutput() + { + // Setup + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = true, + ManualAssemblyProbability = new Random(39).NextDouble() + }; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + 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 = MacroStabilityInwardsFailureMechanismAssemblyFactory.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 MacroStabilityInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) + { + UseManualAssemblyProbability = useManualAssembly + }; + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + 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 = () => MacroStabilityInwardsFailureMechanismAssemblyFactory.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]