Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs =================================================================== diff -u -r1c200c32948d83b6a93a92da6a728120634e6e4f -r67ea037ebc9a3512d7fd4045cd968cddd3e07d4c --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs (.../PipingFailureMechanismSectionResultAssemblyFactory.cs) (revision 1c200c32948d83b6a93a92da6a728120634e6e4f) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultAssemblyFactory.cs (.../PipingFailureMechanismSectionResultAssemblyFactory.cs) (revision 67ea037ebc9a3512d7fd4045cd968cddd3e07d4c) @@ -177,8 +177,8 @@ failureMechanism.PipingProbabilityAssessmentInput.GetN(failureMechanism.PipingProbabilityAssessmentInput.SectionLength)); return calculator.AssembleTailorMadeAssessment( - TailorMadeAssessmentProbabilityCalculationResultType.Probability, //failureMechanismSectionResult.TailorMadeAssessmentResult, - 0.0, //failureMechanismSectionResult.TailorMadeAssessmentProbability, + failureMechanismSectionResult.TailorMadeAssessmentResult, + failureMechanismSectionResult.TailorMadeAssessmentProbability, categories, failureMechanism.PipingProbabilityAssessmentInput.GetN(failureMechanismSectionResult.Section.Length)); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -rb29487c198d87b176783f2396c2b59cd76b9f246 -r67ea037ebc9a3512d7fd4045cd968cddd3e07d4c --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultAssemblyFactoryTest.cs (.../PipingFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision b29487c198d87b176783f2396c2b59cd76b9f246) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultAssemblyFactoryTest.cs (.../PipingFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 67ea037ebc9a3512d7fd4045cd968cddd3e07d4c) @@ -25,6 +25,7 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.Data.TestUtil; using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; @@ -43,6 +44,17 @@ [TestFixture] public class PipingFailureMechanismSectionResultAssemblyFactoryTest { + private static void AssertCategoryCalculatorInput(IAssessmentSection assessmentSection, + AssemblyCategoriesCalculatorStub categoryCalculator, + PipingFailureMechanism failureMechanism) + { + Assert.AreEqual(assessmentSection.FailureMechanismContribution.SignalingNorm, categoryCalculator.SignalingNorm); + Assert.AreEqual(assessmentSection.FailureMechanismContribution.LowerLimitNorm, categoryCalculator.LowerLimitNorm); + Assert.AreEqual(failureMechanism.Contribution, categoryCalculator.FailureMechanismContribution); + Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.GetN(failureMechanism.PipingProbabilityAssessmentInput.SectionLength), + categoryCalculator.N); + } + #region Simple Assessment [Test] @@ -212,8 +224,9 @@ public void AssembleDetailedAssembly_WithInput_SetsInputOnCalculator() { // Setup - var mocks = new MockRepository(); var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -245,12 +258,7 @@ calculator.DetailedAssessmentProbabilityInput); Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.GetN(sectionResult.Section.Length), calculator.DetailedAssessmentNInput); - Assert.AreEqual(assessmentSection.FailureMechanismContribution.SignalingNorm, categoryCalculator.SignalingNorm); - Assert.AreEqual(assessmentSection.FailureMechanismContribution.LowerLimitNorm, categoryCalculator.LowerLimitNorm); - Assert.AreEqual(failureMechanism.Contribution, categoryCalculator.FailureMechanismContribution); - Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.GetN( - failureMechanism.PipingProbabilityAssessmentInput.SectionLength), - categoryCalculator.N); + AssertCategoryCalculatorInput(assessmentSection, categoryCalculator, failureMechanism); Assert.AreSame(categoryCalculator.FailureMechanismSectionCategoriesOutput, calculator.DetailedAssessmentCategoriesInput); mocks.VerifyAll(); } @@ -260,8 +268,9 @@ public void AssembleDetailedAssembly_AssemblyRan_ReturnsOutput() { // Setup - var mocks = new MockRepository(); var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -294,8 +303,9 @@ public void AssembleDetailedAssembly_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup - var mocks = new MockRepository(); var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); @@ -327,5 +337,354 @@ } #endregion + + #region Tailor Made Assessment + + [Test] + public void AssembleTailorMadeAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + null, + new PipingFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleTailorMadeAssembly_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleTailorMadeAssembly_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new PipingFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleTailorMadeAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + AssemblyCategoriesCalculatorStub categoryCalculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + + // Call + PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.TailorMadeAssessmentProbability, calculator.TailorMadeAssessmentProbabilityInput); + Assert.AreEqual(sectionResult.TailorMadeAssessmentResult, calculator.TailorMadeAssessmentProbabilityCalculationResultInput); + Assert.AreEqual(failureMechanism.PipingProbabilityAssessmentInput.GetN(sectionResult.Section.Length), + calculator.TailorMadeAssessmentNInput); + AssertCategoryCalculatorInput(assessmentSection, categoryCalculator, failureMechanism); + Assert.AreSame(categoryCalculator.FailureMechanismSectionCategoriesOutput, calculator.TailorMadeAssessmentCategoriesInput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleTailorMadeAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.TailorMadeAssessmentAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleTailorMadeAssembly_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + new PipingFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + mocks.VerifyAll(); + } + } + + #endregion + + #region Combined Assembly + + [Test] + public void AssembleCombinedAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + null, + Enumerable.Empty(), + new PipingFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleCombinedAssembly_CalculationScenariosNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + null, + new PipingFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculationScenarios", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleCombinedAssembly_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + Enumerable.Empty(), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void AssembleCombinedAssembly_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + Enumerable.Empty(), + new PipingFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleCombinedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = PipingFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = PipingFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = PipingFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + AssemblyToolTestHelper.AssertAreEqual(expectedSimpleAssembly, calculator.CombinedSimpleAssemblyInput); + AssemblyToolTestHelper.AssertAreEqual(expectedDetailedAssembly, calculator.CombinedDetailedAssemblyInput); + AssemblyToolTestHelper.AssertAreEqual(expectedTailorMadeAssembly, calculator.CombinedTailorMadeAssemblyInput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleCombinedAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.CombinedAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleCombinedAssembly_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new PipingFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculateCombinedAssembly = true; + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + Enumerable.Empty(), + new PipingFailureMechanism(), + 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 Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj =================================================================== diff -u -r739752c5cc7ed800dacf74e12221c227183ddc6f -r67ea037ebc9a3512d7fd4045cd968cddd3e07d4c --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 67ea037ebc9a3512d7fd4045cd968cddd3e07d4c) @@ -65,6 +65,10 @@ {358B6DA2-A1DF-477F-B6AC-C30204265CB0} Ringtoets.AssemblyTool.KernelWrapper + + {C6EE9E6A-6578-49DF-914F-CDB531E61891} + Ringtoets.AssemblyTool.Data.TestUtil + {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38} Ringtoets.AssemblyTool.KernelWrapper.TestUtil