Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs =================================================================== diff -u -r322ce828729ae3abc8af382244727615520e9339 -re972fc9c24dc35dc9cb68d73e9f98c4a3e75859e --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision 322ce828729ae3abc8af382244727615520e9339) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision e972fc9c24dc35dc9cb68d73e9f98c4a3e75859e) @@ -95,7 +95,12 @@ protected override object CreateFailureMechanismSectionResultRow(ClosingStructuresFailureMechanismSectionResult sectionResult) { - return new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + if (FailureMechanism == null) + { + return null; + } + + return new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, (ClosingStructuresFailureMechanism) FailureMechanism, assessmentSection); } protected override void Dispose(bool disposing) Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -rad12f4e2c4a765cc6c20e9f17ac051a99644ec44 -re972fc9c24dc35dc9cb68d73e9f98c4a3e75859e --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision ad12f4e2c4a765cc6c20e9f17ac051a99644ec44) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision e972fc9c24dc35dc9cb68d73e9f98c4a3e75859e) @@ -22,6 +22,7 @@ using System; using System.ComponentModel; using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; @@ -33,14 +34,36 @@ /// public class ClosingStructuresFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { + private readonly ClosingStructuresFailureMechanism failureMechanism; + private readonly IAssessmentSection assessmentSection; + /// /// Creates a new instance of . /// /// The to wrap /// so that it can be displayed as a row. - /// Thrown when is null. - public ClosingStructuresFailureMechanismSectionResultRow(ClosingStructuresFailureMechanismSectionResult sectionResult) : base(sectionResult) {} + /// The failure mechanism the result belongs to. + /// The assessment section the result belongs to. + /// Thrown when any parameter is null. + public ClosingStructuresFailureMechanismSectionResultRow(ClosingStructuresFailureMechanismSectionResult sectionResult, + ClosingStructuresFailureMechanism 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/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r322ce828729ae3abc8af382244727615520e9339 -re972fc9c24dc35dc9cb68d73e9f98c4a3e75859e --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 322ce828729ae3abc8af382244727615520e9339) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision e972fc9c24dc35dc9cb68d73e9f98c4a3e75859e) @@ -274,7 +274,7 @@ AssessmentLayerThree = (RoundedDouble) random.NextDouble() }; - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { // When view.Data = new[] @@ -342,7 +342,7 @@ AssessmentLayerOne = assessmentLayerOneState, AssessmentLayerThree = (RoundedDouble) random.NextDouble() }; - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { view.Data = new[] { @@ -397,7 +397,7 @@ public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { FailureMechanismSection section = CreateSimpleFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) @@ -430,7 +430,7 @@ AssessmentLayerOneState assessmentLayerOneState) { // Given - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { var calculation = new StructuresCalculation(); FailureMechanismSection section = CreateSimpleFailureMechanismSection(); @@ -465,7 +465,7 @@ public void GivenSectionResultAndFailedCalculation_ThenLayerTwoAErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { var calculation = new StructuresCalculation { @@ -503,7 +503,7 @@ public void GivenSectionResultAndSuccessfulCalculation_ThenLayerTwoANoError(AssessmentLayerOneState assessmentLayerOneState) { // Given - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { const double probability = 0.56789; var calculation = new StructuresCalculation @@ -541,7 +541,7 @@ public void GivenSectionResultAndAssessmentLayerOneStateSufficient_ThenLayerTwoANoError( ClosingStructuresFailureMechanismSectionResult sectionResult, string expectedValue) { - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { view.Data = new[] { @@ -569,7 +569,7 @@ AssessmentLayerOneState assessmentLayerOneState) { // Given - using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { const double probability = 0.56789; var successfulCalculation = new StructuresCalculation Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rf4049b9b0967513aeadfddb1fe58efa3b3aa1677 -re972fc9c24dc35dc9cb68d73e9f98c4a3e75859e --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision f4049b9b0967513aeadfddb1fe58efa3b3aa1677) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision e972fc9c24dc35dc9cb68d73e9f98c4a3e75859e) @@ -22,8 +22,10 @@ using System; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Forms.Views; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; @@ -40,11 +42,17 @@ public void Constructor_WithParameters_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); + var failureMechanism = new ClosingStructuresFailureMechanism(); + // Call - var row = new ClosingStructuresFailureMechanismSectionResultRow(result); + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf>(row); @@ -55,25 +63,68 @@ nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerTwoA)); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.AssessmentLayerThree)); + mocks.VerifyAll(); } [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new ClosingStructuresFailureMechanismSectionResultRow(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 ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => new ClosingStructuresFailureMechanismSectionResultRow(result, new ClosingStructuresFailureMechanism(), 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 ClosingStructuresFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); // Precondition Assert.IsNull(sectionResult.Calculation); - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; // Assert Assert.IsNaN(assessmentLayerTwoA); + mocks.VerifyAll(); } [Test] @@ -82,6 +133,11 @@ public void AssessmentLayerTwoA_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) { // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + var calculation = new StructuresCalculation(); if (status == CalculationScenarioStatus.Failed) { @@ -94,23 +150,29 @@ Calculation = calculation }; - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(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.586789; + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + + const double reliability = 0.586789; var calculation = new StructuresCalculation { - Output = new TestStructuresOutput(probability) + Output = new TestStructuresOutput(reliability) }; FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); @@ -119,38 +181,51 @@ Calculation = calculation }; - var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; // Assert - Assert.AreEqual(probability, assessmentLayerTwoA); + Assert.AreEqual(reliability, assessmentLayerTwoA); + mocks.VerifyAll(); } [Test] public void GetSectionResultCalculation_NoCalculationSetOnSectionResult_ReturnNull() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); // Precondition Assert.IsNull(result.Calculation); - var row = new ClosingStructuresFailureMechanismSectionResultRow(result); + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Call StructuresCalculation 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 ClosingStructuresFailureMechanism(); var expectedCalculation = new StructuresCalculation(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); @@ -159,30 +234,38 @@ Calculation = expectedCalculation }; - var row = new ClosingStructuresFailureMechanismSectionResultRow(result); + var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection); // Call StructuresCalculation calculation = row.GetSectionResultCalculation(); // Assert Assert.AreSame(expectedCalculation, calculation); + mocks.VerifyAll(); } [Test] public void AssessmentLayerThree_ValueSet_ReturnExpectedValue() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + var random = new Random(21); double assessmentLayerThree = random.NextDouble(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); - var row = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + var row = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection); // Call row.AssessmentLayerThree = assessmentLayerThree; // Assert Assert.AreEqual(assessmentLayerThree, sectionResult.AssessmentLayerThree); + mocks.VerifyAll(); } } } \ No newline at end of file