Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -r3cb5cd49de86f4379c54d71949a76e23c42f228a -r00168da71b7ca2b94166ca16179535ed6d2131b4 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 3cb5cd49de86f4379c54d71949a76e23c42f228a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs (.../HeightStructuresFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 00168da71b7ca2b94166ca16179535ed6d2131b4) @@ -24,6 +24,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; @@ -445,5 +446,169 @@ } #endregion + + #region Combined Assembly + + [Test] + public void AssembleCombinedAssembly_FailureMechanismSectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + null, + new HeightStructuresFailureMechanism(), + 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 = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new HeightStructuresFailureMechanismSectionResult(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 = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new HeightStructuresFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleCombinedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = HeightStructuresFailureMechanismSectionResultAssemblyFactory.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 HeightStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.CombinedAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleCombinedAssembly_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new HeightStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculateCombinedAssembly = true; + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + new HeightStructuresFailureMechanism(), + 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