Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs =================================================================== diff -u -rd49a06fcbf63b36885b0d8f09a01f6539bcbfd56 -racb9db836c6b6cdd639842b4cb559cec5141ba8a --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision d49a06fcbf63b36885b0d8f09a01f6539bcbfd56) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) @@ -27,6 +27,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -38,7 +39,7 @@ public class ClosingStructuresFailureMechanismResultView : FailureMechanismResultView { private const int assessmentLayerOneColumnIndex = 1; - + private const int assessmentLayerTwoAIndex = 2; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; @@ -48,6 +49,7 @@ /// public ClosingStructuresFailureMechanismResultView() { + DataGridViewControl.AddCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.AddCellFormattingHandler(OnCellFormatting); // The concat is needed to observe the input of calculations in child groups. @@ -90,6 +92,7 @@ protected override void Dispose(bool disposing) { + DataGridViewControl.RemoveCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.RemoveCellFormattingHandler(OnCellFormatting); calculationInputObserver.Dispose(); @@ -130,5 +133,25 @@ } } } + + private void ShowAssessmentLayerErrors(object sender, DataGridViewCellFormattingEventArgs e) + { + if (e.ColumnIndex != assessmentLayerTwoAIndex) + { + return; + } + + var resultRow = (ClosingStructuresFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); + if (resultRow != null) + { + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); + + FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, + resultRow.AssessmentLayerOne, + resultRow.AssessmentLayerTwoA, + normativeCalculation); + } + } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -rfd75ff7d1794c6a64fd3ce1aa1f159effba2e102 -racb9db836c6b6cdd639842b4cb559cec5141ba8a --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision fd75ff7d1794c6a64fd3ce1aa1f159effba2e102) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismSectionResultRow.cs (.../ClosingStructuresFailureMechanismSectionResultRow.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) @@ -22,6 +22,7 @@ using System; using System.ComponentModel; using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; @@ -51,5 +52,16 @@ return SectionResult.AssessmentLayerTwoA; } } + + /// + /// Gets the of the wrapped + /// . + /// + /// null if the wrapped section result does not have a calculation + /// set. Otherwise the calculation of the wrapped section result is returned. + public StructuresCalculation GetSectionResultCalculation() + { + return SectionResult.Calculation; + } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r3f40e34c76b06d66a6426c7e07fb3a101b4952cb -racb9db836c6b6cdd639842b4cb559cec5141ba8a --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 3f40e34c76b06d66a6426c7e07fb3a101b4952cb) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) @@ -30,7 +30,10 @@ using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Forms.Views; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -106,7 +109,7 @@ } [Test] - public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmtpy() + public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmpty() { // Setup var testData = new object(); @@ -312,6 +315,194 @@ } } + [Test] + public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip() + { + // Given + using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // When + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Then + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("Er moet een maatgevende berekening voor dit vak worden geselecteerd.", dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndCalculationNotCalculated_ThenLayerTwoAErrorTooltip() + { + // Given + using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + var calculation = new StructuresCalculation(); + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // When + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Then + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak moet nog worden uitgevoerd.", dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndFailedCalculation_ThenLayerTwoAErrorTooltip() + { + // Given + using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + var calculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(1.0, 1.0, double.NaN, 1.0, 1.0) + }; + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // When + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Then + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak heeft geen geldige uitkomst.", dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndSuccessfulCalculation_ThenLayerTwoANoError() + { + // Given + using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + const double probability = 0.56789; + var calculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(1.0, 1.0, probability, 1.0, 1.0) + }; + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // When + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Then + Assert.AreEqual(ProbabilityFormattingHelper.Format(probability), formattedValue); + Assert.IsEmpty(dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndSuccessfulCalculation_WhenChangingCalculationToFailed_ThenLayerTwoAHasError() + { + // Given + using (ClosingStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + const double probability = 0.56789; + var successfulCalculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(1.0, 1.0, probability, 1.0, 1.0) + }; + + var failedCalculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(1.0, 1.0, double.NaN, 1.0, 1.0) + }; + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = successfulCalculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // Precondition + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + Assert.AreEqual(ProbabilityFormattingHelper.Format(probability), formattedValue); + Assert.IsEmpty(dataGridViewCell.ErrorText); + + // When + sectionResult.Calculation = failedCalculation; + formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Then + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak heeft geen geldige uitkomst.", dataGridViewCell.ErrorText); + } + } + + private static FailureMechanismSection CreateSimpleFailureMechanismSection() + { + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + return section; + } + private static void AssertCellIsDisabled(DataGridViewCell dataGridViewCell) { Assert.AreEqual(true, dataGridViewCell.ReadOnly); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rfe1332c1e9b14365a62f6ce03c9494393223179e -racb9db836c6b6cdd639842b4cb559cec5141ba8a --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision fe1332c1e9b14365a62f6ce03c9494393223179e) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) @@ -24,7 +24,10 @@ using NUnit.Framework; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Forms.Views; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; @@ -52,6 +55,116 @@ r => r.AssessmentLayerTwoA)); } + [Test] + public void AssessmentLayerTwoA_NoCalculationSet_ReturnNaN() + { + // Setup + FailureMechanismSection section = CreateSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(sectionResult.Calculation); + + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + + // Call + double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + + // Assert + Assert.IsNaN(assessmentLayerTwoA); + } + + [Test] + [TestCase(CalculationScenarioStatus.Failed)] + [TestCase(CalculationScenarioStatus.NotCalculated)] + public void AssessmentLayerTwoA_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) + { + // Setup + var calculation = new StructuresCalculation(); + if (status == CalculationScenarioStatus.Failed) + { + calculation.Output = new ProbabilityAssessmentOutput(0.9, 1.0, double.NaN, 1.0, 1.0); + } + + FailureMechanismSection section = CreateSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + + // Call + double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + + // Assert + Assert.IsNaN(assessmentLayerTwoA); + } + + [Test] + public void AssessmentLayerTwoA_CalculationSuccessful_ReturnAssessmentLayerTwoA() + { + // Setup + var calculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(0.9, 1.0, 0.95, 1.0, 1.0) + }; + + FailureMechanismSection section = CreateSection(); + var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult); + + // Call + double assessmentLayerTwoA = resultRow.AssessmentLayerTwoA; + + // Assert + Assert.AreEqual(calculation.Output.Probability, assessmentLayerTwoA); + } + + [Test] + public void GetSectionResultCalculation_NoCalculationSetOnSectionResult_ReturnNull() + { + // Setup + FailureMechanismSection section = CreateSection(); + var result = new ClosingStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(result.Calculation); + + var row = new ClosingStructuresFailureMechanismSectionResultRow(result); + + // Call + StructuresCalculation calculation = row.GetSectionResultCalculation(); + + // Assert + Assert.IsNull(calculation); + } + + [Test] + public void GetSectionResultCalculation_WithCalculationSetOnSectionResult_ReturnCalculation() + { + // Setup + var expectedCalculation = new StructuresCalculation(); + + FailureMechanismSection section = CreateSection(); + var result = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = expectedCalculation + }; + + var row = new ClosingStructuresFailureMechanismSectionResultRow(result); + + // Call + StructuresCalculation calculation = row.GetSectionResultCalculation(); + + // Assert + Assert.AreSame(expectedCalculation, calculation); + } + private static FailureMechanismSection CreateSection() { return new FailureMechanismSection("name", new[]