Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs =================================================================== diff -u -r3f282c2215f8aa9a287a6eba73868cbd0d30f7e5 -r6edfd6348d58a4c36144c823bb7dc8b2a5828482 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs (.../FailureMechanismSectionAssemblyCalculatorStubTest.cs) (revision 3f282c2215f8aa9a287a6eba73868cbd0d30f7e5) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs (.../FailureMechanismSectionAssemblyCalculatorStubTest.cs) (revision 6edfd6348d58a4c36144c823bb7dc8b2a5828482) @@ -57,8 +57,10 @@ Assert.AreEqual((TailorMadeAssessmentResultType) 0, calculator.TailorMadeAssessmentResultInput); Assert.IsNull(calculator.TailorMadeAssessmentAssemblyOutput); - Assert.IsNull(calculator.CombinedAssemblyInput); - Assert.IsNull(calculator.CombinedAssemblyOutput); + Assert.IsNull(calculator.CombinedSimpleAssemblyInput); + Assert.IsNull(calculator.CombinedDetailedAssemblyInput); + Assert.IsNull(calculator.CombinedTailorMadeAssemblyInput); + Assert.IsNull(calculator.CombinedAssemblyOutput); } #region Simple Assessment @@ -379,7 +381,7 @@ #region Combined Assembly [Test] - public void AssembleCombined_ThrowExceptionOnCalculateFalse_ReturnOutput() + public void AssembleCombined_ThrowExceptionOnCalculateCombinedAssemblyFalse_ReturnOutput() { // Setup var random = new Random(39); @@ -398,7 +400,7 @@ } [Test] - public void AssembleCombined_ThrowExceptionOnCalculateFalse_SetsInput() + public void AssembleCombined_ThrowExceptionOnCalculateCombinedAssemblyFalse_SetsInput() { // Setup var random = new Random(39); @@ -418,21 +420,18 @@ calculator.AssembleCombined(simpleAssembly, detailedAssembly, tailorMadeAssembly); // Assert - CollectionAssert.AreEqual(new[] - { - simpleAssembly, - detailedAssembly, - tailorMadeAssembly - }, calculator.CombinedAssemblyInput); + Assert.AreSame(simpleAssembly, calculator.CombinedSimpleAssemblyInput); + Assert.AreSame(detailedAssembly, calculator.CombinedDetailedAssemblyInput); + Assert.AreSame(tailorMadeAssembly, calculator.CombinedTailorMadeAssemblyInput); } [Test] - public void AssembleCombined_ThrowExceptionOnCalculateTrue_ThrowsFailureMechanismSectionAssemblyCalculatorException() + public void AssembleCombined_ThrowExceptionOnCalculateCombinedAssemblyTrue_ThrowsFailureMechanismSectionAssemblyCalculatorException() { // Setup var calculator = new FailureMechanismSectionAssemblyCalculatorStub { - ThrowExceptionOnCalculate = true + ThrowExceptionOnCalculateCombinedAssembly = true }; // Call Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs =================================================================== diff -u -r3f282c2215f8aa9a287a6eba73868cbd0d30f7e5 -r6edfd6348d58a4c36144c823bb7dc8b2a5828482 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 3f282c2215f8aa9a287a6eba73868cbd0d30f7e5) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 6edfd6348d58a4c36144c823bb7dc8b2a5828482) @@ -98,15 +98,30 @@ public FailureMechanismSectionAssembly CombinedAssemblyOutput { get; private set; } /// - /// Gets the input of the combined assembly calculation. + /// Gets the simple assembly input of the combined assembly calculation. /// - public IEnumerable CombinedAssemblyInput { get; private set; } + public FailureMechanismSectionAssembly CombinedSimpleAssemblyInput { get; private set; } /// + /// Gets the detailed assembly input of the combined assembly calculation. + /// + public FailureMechanismSectionAssembly CombinedDetailedAssemblyInput { get; private set; } + + /// + /// Gets the tailor made assembly input of the combined assembly calculation. + /// + public FailureMechanismSectionAssembly CombinedTailorMadeAssemblyInput { get; private set; } + + /// /// Sets an indicator whether an exception must be thrown when performing a calculation. /// public bool ThrowExceptionOnCalculate { private get; set; } + /// + /// Sets an indicator whether an exception must be thrown when performing a combined assembly calculation. + /// + public bool ThrowExceptionOnCalculateCombinedAssembly { get; set; } + public FailureMechanismSectionAssembly AssembleSimpleAssessment(SimpleAssessmentResultType input) { if (ThrowExceptionOnCalculate) @@ -183,17 +198,14 @@ FailureMechanismSectionAssembly detailedAssembly, FailureMechanismSectionAssembly tailorMadeAssembly) { - if (ThrowExceptionOnCalculate) + if (ThrowExceptionOnCalculateCombinedAssembly) { throw new FailureMechanismSectionAssemblyCalculatorException("Message", new Exception()); } - CombinedAssemblyInput = new List - { - simpleAssembly, - detailedAssembly, - tailorMadeAssembly - }; + CombinedSimpleAssemblyInput = simpleAssembly; + CombinedDetailedAssemblyInput = detailedAssembly; + CombinedTailorMadeAssemblyInput = tailorMadeAssembly; return CombinedAssemblyOutput = tailorMadeAssembly; } Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.cs =================================================================== diff -u -r59512bde82de1297788119a8cacd067789389d41 -r6edfd6348d58a4c36144c823bb7dc8b2a5828482 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.cs (.../MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 59512bde82de1297788119a8cacd067789389d41) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.cs (.../MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 6edfd6348d58a4c36144c823bb7dc8b2a5828482) @@ -181,5 +181,56 @@ throw new AssemblyException(e.Message, e); } } + + /// + /// Assembles the combined assembly. + /// + /// The failure mechanism section result to + /// combine the assemblies for. + /// The failure mechanism belonging to this section. + /// The belonging to this section. + /// A . + /// Thrown when any parameter is null. + /// Thrown when the + /// could not be created. + public static FailureMechanismSectionAssembly AssembleCombinedAssembly( + MacroStabilityOutwardsFailureMechanismSectionResult failureMechanismSectionResult, + MacroStabilityOutwardsFailureMechanism 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 simpleAssembly = AssembleSimpleAssessment(failureMechanismSectionResult); + FailureMechanismSectionAssembly detailedAssembly = AssembleDetailedAssembly( + failureMechanismSectionResult, failureMechanism, assessmentSection); + FailureMechanismSectionAssembly tailorMadeAssembly = AssembleTailorMadeAssembly( + failureMechanismSectionResult, failureMechanism, assessmentSection); + + IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance; + IFailureMechanismSectionAssemblyCalculator calculator = + calculatorFactory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + try + { + return calculator.AssembleCombined(simpleAssembly, detailedAssembly, tailorMadeAssembly); + } + catch (FailureMechanismSectionAssemblyCalculatorException e) + { + throw new AssemblyException(e.Message, e); + } + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -r59512bde82de1297788119a8cacd067789389d41 -r6edfd6348d58a4c36144c823bb7dc8b2a5828482 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactoryTest.cs (.../MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 59512bde82de1297788119a8cacd067789389d41) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/StandAlone/AssemblyFactories/MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactoryTest.cs (.../MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 6edfd6348d58a4c36144c823bb7dc8b2a5828482) @@ -189,8 +189,9 @@ public void AssembleDetailedAssembly_WithInput_SetsInputOnCalculator() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -225,8 +226,9 @@ public void AssembleDetailedAssembly_AssemblyRan_ReturnsOutput() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -255,8 +257,9 @@ public void AssembleDetailedAssembly_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -345,8 +348,9 @@ public void AssembleTailorMadeAssembly_WithInput_SetsInputOnCalculator() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -382,8 +386,9 @@ public void AssembleTailorMadeAssembly_AssemblyRan_ReturnsOutput() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -412,8 +417,9 @@ public void AssembleTailorMadeAssembly_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup - var mocks = new MockRepository(); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -441,5 +447,172 @@ } #endregion + + #region Combined Assembly + + [Test] + public void AssembleCombinedAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + null, + new MacroStabilityOutwardsFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleCombinedAssembly_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleCombinedAssembly_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new MacroStabilityOutwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleCombinedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + Assert.AreEqual(expectedSimpleAssembly.Group, calculator.CombinedSimpleAssemblyInput.Group); + Assert.AreEqual(expectedSimpleAssembly.Probability, calculator.CombinedSimpleAssemblyInput.Probability); + Assert.AreEqual(expectedDetailedAssembly.Group, calculator.CombinedDetailedAssemblyInput.Group); + Assert.AreEqual(expectedDetailedAssembly.Probability, calculator.CombinedDetailedAssemblyInput.Probability); + Assert.AreEqual(expectedTailorMadeAssembly.Group, calculator.CombinedTailorMadeAssemblyInput.Group); + Assert.AreEqual(expectedTailorMadeAssembly.Probability, calculator.CombinedTailorMadeAssemblyInput.Probability); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleCombinedAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.CombinedAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleCombinedAssembly_CalculatorThrowsExceptions_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculateCombinedAssembly = true; + + // Call + TestDelegate call = () => MacroStabilityOutwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + new MacroStabilityOutwardsFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + mocks.VerifyAll(); + } + } + + #endregion } } \ No newline at end of file