Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs =================================================================== diff -u -rb1c7ec488d3c3f97a4c3b53669623aa8b678d36b -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision b1c7ec488d3c3f97a4c3b53669623aa8b678d36b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Properties; @@ -35,6 +34,7 @@ public class GrassCoverErosionInwardsFailureMechanismSectionResult : FailureMechanismSectionResult { private double tailorMadeAssessmentProbability; + private double manualAssemblyProbability; /// /// Creates a new instance of . @@ -47,7 +47,7 @@ DetailedAssessmentResult = DetailedAssessmentResultType.Probability; TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.None; tailorMadeAssessmentProbability = double.NaN; - ManualAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ManualAssemblyProbability = double.NaN; } /// @@ -91,13 +91,27 @@ } /// - /// Gets or sets the indicator whether the combined assembly should be overwritten by . + /// Gets or sets the indicator whether the combined assembly should be overwritten by . /// - public bool UseManualAssemblyCategoryGroup { get; set; } + public bool UseManualAssemblyProbability { get; set; } /// /// Gets or sets the manually selected assembly category group. /// - public FailureMechanismSectionAssemblyCategoryGroup ManualAssemblyCategoryGroup { get; set; } + /// Thrown when is not in range [0,1]. + public double ManualAssemblyProbability + { + get + { + return manualAssemblyProbability; + } + set + { + ProbabilityHelper.ValidateProbability(value, null, + Resources.ArbitraryProbabilityFailureMechanismSectionResult_AssessmentProbability_Value_needs_to_be_in_Range_0_, + true); + manualAssemblyProbability = value; + } + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.cs =================================================================== diff -u -r5804285815fe6816e99dc8c1b4c86bd05752edfb -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 5804285815fe6816e99dc8c1b4c86bd05752edfb) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -123,5 +123,111 @@ throw new AssemblyException(e.Message, e); } } + + /// + /// Assembles the tailor made assessment result. + /// + /// The failure mechanism section result to + /// assemble the tailor made assembly 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 AssembleTailorMadeAssembly( + GrassCoverErosionInwardsFailureMechanismSectionResult failureMechanismSectionResult, + GrassCoverErosionInwardsFailureMechanism 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)); + } + + IAssemblyToolCalculatorFactory calculatorFactory = AssemblyToolCalculatorFactory.Instance; + IFailureMechanismSectionAssemblyCalculator calculator = + calculatorFactory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + try + { + IEnumerable categories = + AssemblyToolCategoriesFactory.CreateFailureMechanismSectionAssemblyCategories( + assessmentSection.FailureMechanismContribution.SignalingNorm, + assessmentSection.FailureMechanismContribution.LowerLimitNorm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N); + + return calculator.AssembleTailorMadeAssessment( + failureMechanismSectionResult.TailorMadeAssessmentResult, + failureMechanismSectionResult.TailorMadeAssessmentProbability, + categories); + } + catch (FailureMechanismSectionAssemblyCalculatorException e) + { + 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( + GrassCoverErosionInwardsFailureMechanismSectionResult failureMechanismSectionResult, + GrassCoverErosionInwardsFailureMechanism 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/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Ringtoets.GrassCoverErosionInwards.Forms.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.csproj) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -132,6 +132,11 @@ Core.Components.OxyPlot.Forms False + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Ringtoets.AssemblyTool.Data + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -rb1c7ec488d3c3f97a4c3b53669623aa8b678d36b -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision b1c7ec488d3c3f97a4c3b53669623aa8b678d36b) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -21,7 +21,9 @@ using System; using System.ComponentModel; +using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; @@ -82,6 +84,50 @@ } /// + /// Gets or sets the value representing the detailed assessment result. + /// + public DetailedAssessmentResultType DetailedAssessmentResult + { + get + { + return SectionResult.DetailedAssessmentResult; + } + set + { + SectionResult.DetailedAssessmentResult = value; + SectionResult.NotifyObservers(); + } + } + + /// + /// Gets the value representing the result of the detailed assessment. + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public double DetailedAssessmentProbability + { + get + { + return SectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection); + } + } + + /// + /// Gets or sets the value representing the tailor made assessment result. + /// + public TailorMadeAssessmentProbabilityCalculationResultType TailorMadeAssessmentResult + { + get + { + return SectionResult.TailorMadeAssessmentResult; + } + set + { + SectionResult.TailorMadeAssessmentResult = value; + SectionResult.NotifyObservers(); + } + } + + /// /// Gets or sets the tailor made assessment probability of the . /// /// Thrown when is @@ -101,15 +147,99 @@ } /// - /// Gets the value representing the result of the detailed assessment. + /// Gets the simple assembly category group. /// + /// Thrown when the + /// could not be created. + public FailureMechanismSectionAssemblyCategoryGroup SimpleAssemblyCategoryGroup + { + get + { + return GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult).Group; + } + } + + /// + /// Gets the detailed assembly category group. + /// + /// Thrown when the + /// could not be created. + public FailureMechanismSectionAssemblyCategoryGroup DetailedAssemblyCategoryGroup + { + get + { + return GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + } + + /// + /// Gets the tailor made assembly category group. + /// + /// Thrown when the + /// could not be created. + public FailureMechanismSectionAssemblyCategoryGroup TailorMadeAssemblyCategoryGroup + { + get + { + return GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + } + + /// + /// Gets the combined assembly category group. + /// + /// Thrown when the + /// could not be created. + public FailureMechanismSectionAssemblyCategoryGroup CombinedAssemblyCategoryGroup + { + get + { + return GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + } + + /// + /// Gets or sets the indicator whether the combined assembly should be overwritten by . + /// + public bool UseManualAssemblyProbability + { + get + { + return SectionResult.UseManualAssemblyProbability; + } + set + { + SectionResult.UseManualAssemblyProbability = value; + SectionResult.NotifyObservers(); + } + } + + /// + /// Gets or sets the manually selected assembly probability. + /// + /// Thrown when is + /// not in the range [0,1]. [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double DetailedAssessmentProbability + public double ManualAssemblyProbability { get { - return SectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection); + return SectionResult.ManualAssemblyProbability; } + set + { + SectionResult.ManualAssemblyProbability = value; + SectionResult.NotifyObservers(); + } } /// Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactoryTest.cs =================================================================== diff -u -rcb4699ab3f0ba6a23e21650ec8cec52d82d0777b -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactoryTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision cb4699ab3f0ba6a23e21650ec8cec52d82d0777b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactoryTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactoryTest.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -279,5 +279,331 @@ } #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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + null, + new GrassCoverErosionInwardsFailureMechanism(), + 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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + new GrassCoverErosionInwardsFailureMechanismSectionResult(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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new GrassCoverErosionInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleTailorMadeAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + AssemblyCategoriesCalculatorStub categoryCalculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + + // Call + GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + Assert.AreEqual(sectionResult.TailorMadeAssessmentProbability, calculator.TailorMadeAssessmentProbabilityInput); + Assert.AreEqual(sectionResult.TailorMadeAssessmentResult, calculator.TailorMadeAssessmentProbabilityCalculationResultType); + + Assert.AreEqual(assessmentSection.FailureMechanismContribution.SignalingNorm, categoryCalculator.SignalingNorm); + Assert.AreEqual(assessmentSection.FailureMechanismContribution.LowerLimitNorm, categoryCalculator.LowerLimitNorm); + Assert.AreEqual(failureMechanism.Contribution, categoryCalculator.ProbabilityDistributionFactor); + Assert.AreEqual(failureMechanism.GeneralInput.N, categoryCalculator.N); + Assert.AreSame(categoryCalculator.FailureMechanismSectionCategoriesOutput, calculator.TailorMadeAssessmentCategoriesInput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleTailorMadeAssembly_AssemblyRan_ReturnsOutput() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.TailorMadeAssessmentAssemblyOutput; + Assert.AreSame(calculatorOutput, actualOutput); + mocks.VerifyAll(); + } + } + + [Test] + public void AssembleTailorMadeAssembly_CalculatorThrowsExceptions_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + TestDelegate call = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( + sectionResult, + new GrassCoverErosionInwardsFailureMechanism(), + 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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + null, + new GrassCoverErosionInwardsFailureMechanism(), + 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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new GrassCoverErosionInwardsFailureMechanismSectionResult(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 = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), + new GrassCoverErosionInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleCombinedAssembly_WithInput_SetsInputOnCalculator() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + + // Assert + FailureMechanismSectionAssembly expectedSimpleAssembly = GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment( + sectionResult); + FailureMechanismSectionAssembly expectedDetailedAssembly = GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( + sectionResult, + failureMechanism, + assessmentSection); + FailureMechanismSectionAssembly expectedTailorMadeAssembly = GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.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 GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssembly actualOutput = + GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.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 GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculateCombinedAssembly = true; + + // Call + TestDelegate call = () => GrassCoverErosionInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( + sectionResult, + new GrassCoverErosionInwardsFailureMechanism(), + 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/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs =================================================================== diff -u -rb1c7ec488d3c3f97a4c3b53669623aa8b678d36b -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision b1c7ec488d3c3f97a4c3b53669623aa8b678d36b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.FailureMechanism; @@ -48,8 +47,8 @@ Assert.AreEqual(DetailedAssessmentResultType.Probability, result.DetailedAssessmentResult); Assert.AreEqual(TailorMadeAssessmentProbabilityCalculationResultType.None, result.TailorMadeAssessmentResult); Assert.IsNaN(result.TailorMadeAssessmentProbability); - Assert.IsFalse(result.UseManualAssemblyCategoryGroup); - Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroup.None, result.ManualAssemblyCategoryGroup); + Assert.IsFalse(result.UseManualAssemblyProbability); + Assert.AreEqual(double.NaN, result.ManualAssemblyProbability); } [Test] @@ -107,5 +106,46 @@ // Assert Assert.AreEqual(newValue, result.TailorMadeAssessmentProbability); } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-20)] + [TestCase(-1e-6)] + [TestCase(1 + 1e-6)] + [TestCase(12)] + public void ManualAssemblyProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double newValue) + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate test = () => result.ManualAssemblyProbability = newValue; + + // Assert + string message = Assert.Throws(test).Message; + const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + [TestCase(0)] + [TestCase(1e-6)] + [TestCase(0.5)] + [TestCase(1 - 1e-6)] + [TestCase(1)] + [TestCase(double.NaN)] + public void ManualAssemblyProbability_ValidValue_NewValueSet(double newValue) + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + result.ManualAssemblyProbability = newValue; + + // Assert + Assert.AreEqual(newValue, result.ManualAssemblyProbability); + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -105,6 +105,18 @@ {318BA582-88C9-4816-A54A-A7E431461DE3} Core.Components.Gis + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Ringtoets.AssemblyTool.Data + + + {358B6DA2-A1DF-477F-B6AC-C30204265CB0} + Ringtoets.AssemblyTool.KernelWrapper + + + {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38} + Ringtoets.AssemblyTool.KernelWrapper.TestUtil + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rb761c34a465fc6d203555b5a52839dd1681aad5a -r70df02232e2470ca8edfa1181512e96c580d264a --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision b761c34a465fc6d203555b5a52839dd1681aad5a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 70df02232e2470ca8edfa1181512e96c580d264a) @@ -24,8 +24,13 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.TypeConverters; @@ -107,6 +112,91 @@ } [Test] + public void UseManualAssemblyProbability_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Precondition + Assert.IsFalse(result.UseManualAssemblyProbability); + + // Call + row.UseManualAssemblyProbability = true; + + // Assert + Assert.IsTrue(result.UseManualAssemblyProbability); + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(0.5)] + [TestCase(1e-6)] + [TestCase(double.NaN)] + public void ManualAssemblyProbability_ValidValue_NotifyObserversAndPropertyChanged(double value) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + row.ManualAssemblyProbability = value; + + // Assert + Assert.AreEqual(value, row.ManualAssemblyProbability); + mocks.VerifyAll(); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-20)] + [TestCase(-1e-6)] + [TestCase(1 + 1e-6)] + [TestCase(12)] + public void ManualAssemblyProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double value) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + TestDelegate test = () => row.ManualAssemblyProbability = value; + + // Assert + string message = Assert.Throws(test).Message; + const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; + Assert.AreEqual(expectedMessage, message); + mocks.VerifyAll(); + } + + #region Registration + + [Test] public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup @@ -136,6 +226,33 @@ } [Test] + public void DetailedAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var random = new Random(39); + var newValue = random.NextEnumValue(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + row.DetailedAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.DetailedAssessmentResult); + mocks.VerifyAll(); + } + + [Test] public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() { // Setup @@ -285,6 +402,33 @@ } [Test] + public void TailorMadeAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var random = new Random(39); + var newValue = random.NextEnumValue(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + result.Attach(observer); + + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + row.TailorMadeAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.TailorMadeAssessmentResult); + mocks.VerifyAll(); + } + + [Test] [TestCase(0)] [TestCase(1)] [TestCase(0.5)] @@ -339,5 +483,243 @@ Assert.AreEqual(expectedMessage, message); mocks.VerifyAll(); } + + #endregion + + #region Assembly Results + + [Test] + public void SimpleAssemblyCategoryGroup_AssemblyRan_ReturnCategoryGroup() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup = row.SimpleAssemblyCategoryGroup; + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.SimpleAssessmentAssemblyOutput; + Assert.AreEqual(calculatorOutput.Group, simpleAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void SimpleAssemblyCategoryGroup_AssemblyThrowsException_ThrowsAssemblyException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; + TestDelegate test = () => simpleAssemblyCategoryGroup = row.SimpleAssemblyCategoryGroup; + + // Assert + Assert.Throws(test); + mocks.VerifyAll(); + } + } + + [Test] + public void DetailedAssemblyCategoryGroup_AssemblyRan_ReturnCategoryGroup() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup = row.DetailedAssemblyCategoryGroup; + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.DetailedAssessmentAssemblyOutput; + Assert.AreEqual(calculatorOutput.Group, detailedAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void DetailedAssemblyCategoryGroup_AssemblyThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; + TestDelegate test = () => detailedAssemblyCategoryGroup = row.DetailedAssemblyCategoryGroup; + + // Assert + Assert.Throws(test); + mocks.VerifyAll(); + } + } + + [Test] + public void TailorMadeAssemblyCategoryGroup_AssemblyRan_ReturnCategoryGroup() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup = row.TailorMadeAssemblyCategoryGroup; + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.TailorMadeAssessmentAssemblyOutput; + Assert.AreEqual(calculatorOutput.Group, tailorMadeAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void TailorMadeAssemblyCategoryGroup_AssemblyThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; + TestDelegate test = () => tailorMadeAssemblyCategoryGroup = row.TailorMadeAssemblyCategoryGroup; + + // Assert + Assert.Throws(test); + mocks.VerifyAll(); + } + } + + [Test] + public void CombinedAssemblyCategoryGroup_AssemblyRan_ReturnCategoryGroup() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup = row.CombinedAssemblyCategoryGroup; + + // Assert + FailureMechanismSectionAssembly calculatorOutput = calculator.CombinedAssemblyOutput; + Assert.AreEqual(calculatorOutput.Group, combinedAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void CombinedAssemblyCategoryGroup_AssemblyThrowsException_ThrowsAssemblyException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; + TestDelegate test = () => combinedAssemblyCategoryGroup = row.CombinedAssemblyCategoryGroup; + + // Assert + Assert.Throws(test); + mocks.VerifyAll(); + } + } + + #endregion } } \ No newline at end of file