Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs =================================================================== diff -u -r2aa1338225863d1875dc48cf37e49b9be3561465 -r1b10713698cbe378c5e0be2b73ddb14e514fcdd7 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 2aa1338225863d1875dc48cf37e49b9be3561465) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 1b10713698cbe378c5e0be2b73ddb14e514fcdd7) @@ -38,8 +38,8 @@ /// public class GrassCoverErosionInwardsFailureMechanismResultView : FailureMechanismResultView { - private readonly IAssessmentSection assessmentSection; private const int assessmentLayerTwoAIndex = 2; + private readonly IAssessmentSection assessmentSection; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; @@ -107,7 +107,13 @@ protected override object CreateFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) { - return new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + if (FailureMechanism == null) + { + return null; + } + + return new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult, (GrassCoverErosionInwardsFailureMechanism) FailureMechanism, + assessmentSection); } protected override void AddDataGridColumns() Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -rd2bccf12592be5246fc438434a8eec34f24d68ff -r1b10713698cbe378c5e0be2b73ddb14e514fcdd7 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision d2bccf12592be5246fc438434a8eec34f24d68ff) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 1b10713698cbe378c5e0be2b73ddb14e514fcdd7) @@ -21,6 +21,7 @@ using System; using System.ComponentModel; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.GrassCoverErosionInwards.Data; @@ -33,16 +34,36 @@ /// internal class GrassCoverErosionInwardsFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { + private readonly GrassCoverErosionInwardsFailureMechanism failureMechanism; + private readonly IAssessmentSection assessmentSection; + /// /// Creates a new instance of . /// /// The that is /// the source of this row. - /// Thrown when is - /// null. - public GrassCoverErosionInwardsFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) - : base(sectionResult) {} + /// The failure mechanism the result belongs to. + /// The assessment section the result belongs to. + /// Thrown when any parameter is null. + public GrassCoverErosionInwardsFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(sectionResult) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + this.failureMechanism = failureMechanism; + this.assessmentSection = assessmentSection; + } + /// /// Gets or sets the value of the tailored assessment of safety. /// Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs =================================================================== diff -u -r2aa1338225863d1875dc48cf37e49b9be3561465 -r1b10713698cbe378c5e0be2b73ddb14e514fcdd7 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision 2aa1338225863d1875dc48cf37e49b9be3561465) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision 1b10713698cbe378c5e0be2b73ddb14e514fcdd7) @@ -312,7 +312,7 @@ public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given - using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { FailureMechanismSection section = CreateSimpleFailureMechanismSection(); var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) @@ -345,7 +345,7 @@ AssessmentLayerOneState assessmentLayerOneState) { // Given - using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { var calculation = new GrassCoverErosionInwardsCalculation(); FailureMechanismSection section = CreateSimpleFailureMechanismSection(); @@ -380,7 +380,7 @@ public void GivenSectionResultAndFailedCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given - using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { var calculation = new GrassCoverErosionInwardsCalculation { @@ -459,7 +459,7 @@ public void GivenSectionResultAndAssessmentLayerOneStateSufficient_ThenLayerTwoANoError( GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult, string expectedValue) { - using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { view.Data = new[] { @@ -487,7 +487,7 @@ AssessmentLayerOneState assessmentLayerOneState) { // Given - using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (GrassCoverErosionInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { const double probability = 0.56789; var successfulCalculation = new GrassCoverErosionInwardsCalculation Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rf4049b9b0967513aeadfddb1fe58efa3b3aa1677 -r1b10713698cbe378c5e0be2b73ddb14e514fcdd7 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision f4049b9b0967513aeadfddb1fe58efa3b3aa1677) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 1b10713698cbe378c5e0be2b73ddb14e514fcdd7) @@ -22,6 +22,8 @@ using System; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; @@ -40,11 +42,17 @@ public void Constructor_WithParameters_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Call - var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf>(row); @@ -58,22 +66,64 @@ } [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, new GrassCoverErosionInwardsFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void AssessmentLayerTwoA_NoCalculationSet_ReturnNaN() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Precondition Assert.IsNull(sectionResult.Calculation); - var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; // Assert Assert.IsNaN(assessmentLayerTwoA); + mocks.VerifyAll(); } [Test] @@ -82,6 +132,12 @@ public void AssessmentLayerTwoA_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var calculation = new GrassCoverErosionInwardsCalculation(); if (status == CalculationScenarioStatus.Failed) { @@ -96,20 +152,27 @@ Calculation = calculation }; - var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; // Assert Assert.IsNaN(assessmentLayerTwoA); + mocks.VerifyAll(); } [Test] public void AssessmentLayerTwoA_CalculationSuccessful_ReturnAssessmentLayerTwoA() { // Setup const double probability = 0.95; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var calculation = new GrassCoverErosionInwardsCalculation { Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(probability), @@ -123,38 +186,52 @@ Calculation = calculation }; - var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; // Assert Assert.AreEqual(probability, assessmentLayerTwoA); + mocks.VerifyAll(); } [Test] public void GetSectionResultCalculation_NoCalculationSetOnSectionResult_ReturnNull() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); // Precondition Assert.IsNull(result.Calculation); - var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Call GrassCoverErosionInwardsCalculation calculation = row.GetSectionResultCalculation(); // Assert Assert.IsNull(calculation); + mocks.VerifyAll(); } [Test] public void GetSectionResultCalculation_WithCalculationSetOnSectionResult_ReturnCalculation() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); @@ -163,31 +240,39 @@ Calculation = grassCoverErosionInwardsCalculation }; - var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Call GrassCoverErosionInwardsCalculation calculation = row.GetSectionResultCalculation(); // Assert Assert.AreSame(grassCoverErosionInwardsCalculation, calculation); + mocks.VerifyAll(); } [Test] public void AssessmentLayerThree_ValueSet_ReturnExpectedValue() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var random = new Random(21); double assessmentLayerThree = random.NextDouble(); var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult( FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); - var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + var row = new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call row.AssessmentLayerThree = assessmentLayerThree; // Assert Assert.AreEqual(assessmentLayerThree, sectionResult.AssessmentLayerThree); + mocks.VerifyAll(); } } } \ No newline at end of file