Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs =================================================================== diff -u -racb9db836c6b6cdd639842b4cb559cec5141ba8a -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Views/ClosingStructuresFailureMechanismResultView.cs (.../ClosingStructuresFailureMechanismResultView.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -142,16 +142,13 @@ } var resultRow = (ClosingStructuresFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); - if (resultRow != null) - { - DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); - StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); - FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, - resultRow.AssessmentLayerOne, - resultRow.AssessmentLayerTwoA, - normativeCalculation); - } + FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, + resultRow.AssessmentLayerOne, + resultRow.AssessmentLayerTwoA, + normativeCalculation); } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r3af4966b460f479dba1acd47805152617af8a77b -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -78,21 +78,15 @@ // Setup using (ClosingStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - var points = new[] - { - new Point2D(1, 2), - new Point2D(3, 4) - }; - - var section = new FailureMechanismSection("test", points); + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); var testData = new List { sectionResult }; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + // Precondition Assert.AreEqual(2, dataGridView.RowCount); @@ -340,14 +334,8 @@ public void GivenFormWithClosingStructuresFailureMechanismResultView_WhenDataSourceWithOtherFailureMechanismSectionResultAssigned_ThenSectionsNotAdded() { // Given - var section1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0, 0) - }); - var section2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(0, 0) - }); + var section1 = CreateSimpleFailureMechanismSection(); + var section2 = CreateSimpleFailureMechanismSection(); var result1 = new TestFailureMechanismSectionResult(section1); var result2 = new TestFailureMechanismSectionResult(section2); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -racb9db836c6b6cdd639842b4cb559cec5141ba8a -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismSectionResultRowTest.cs (.../ClosingStructuresFailureMechanismSectionResultRowTest.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -30,7 +30,6 @@ using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; -using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.ClosingStructures.Forms.Test.Views { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs =================================================================== diff -u -rf419c811044695e9a3a7dd9729d9e25d3705a67a -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision f419c811044695e9a3a7dd9729d9e25d3705a67a) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -142,16 +142,13 @@ } var resultRow = (GrassCoverErosionInwardsFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); - if (resultRow != null) - { - DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); - GrassCoverErosionInwardsCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + GrassCoverErosionInwardsCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); - FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, - resultRow.AssessmentLayerOne, - resultRow.AssessmentLayerTwoA, - normativeCalculation); - } + FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, + resultRow.AssessmentLayerOne, + resultRow.AssessmentLayerTwoA, + normativeCalculation); } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs =================================================================== diff -u -r3af4966b460f479dba1acd47805152617af8a77b -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -77,7 +77,9 @@ base.FailureMechanism = value; var calculatableFailureMechanism = value as ICalculatableFailureMechanism; - CalculationGroup observableGroup = calculatableFailureMechanism != null ? calculatableFailureMechanism.CalculationsGroup : null; + CalculationGroup observableGroup = calculatableFailureMechanism != null + ? calculatableFailureMechanism.CalculationsGroup + : null; calculationInputObserver.Observable = observableGroup; calculationOutputObserver.Observable = observableGroup; @@ -143,16 +145,13 @@ } var resultRow = (HeightStructuresFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); - if (resultRow != null) - { - DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); - StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + StructuresCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); - FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, - resultRow.AssessmentLayerOne, - resultRow.AssessmentLayerTwoA, - normativeCalculation); - } + FailureMechanismSectionResultRowHelper.ShowAssessmentLayerTwoAErrors(currentDataGridViewCell, + resultRow.AssessmentLayerOne, + resultRow.AssessmentLayerTwoA, + normativeCalculation); } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r3af4966b460f479dba1acd47805152617af8a77b -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -29,6 +29,9 @@ using NUnit.Extensions.Forms; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.Views; @@ -271,10 +274,187 @@ } [Test] + public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip() + { + // Given + using (HeightStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new HeightStructuresFailureMechanismSectionResult(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 (HeightStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + var calculation = new StructuresCalculation(); + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new HeightStructuresFailureMechanismSectionResult(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 (HeightStructuresFailureMechanismResultView 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 HeightStructuresFailureMechanismSectionResult(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 (HeightStructuresFailureMechanismResultView 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 HeightStructuresFailureMechanismSectionResult(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 (HeightStructuresFailureMechanismResultView 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 HeightStructuresFailureMechanismSectionResult(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); + } + } + + [Test] public void FailureMechanismResultView_EditValueDirtyStateChangedEventFired_ValueCommittedCellInEditMode() { // Setup - using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + using (HeightStructuresFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { var sections = (List) view.Data; sections[0].AssessmentLayerOne = false; @@ -296,6 +476,17 @@ } } + private static FailureMechanismSection CreateSimpleFailureMechanismSection() + { + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + return section; + } + private HeightStructuresFailureMechanismResultView ShowFullyConfiguredFailureMechanismResultsView() { var failureMechanism = new HeightStructuresFailureMechanism(); Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismResultView.cs =================================================================== diff -u -rd49a06fcbf63b36885b0d8f09a01f6539bcbfd56 -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismResultView.cs (.../StabilityPointStructuresFailureMechanismResultView.cs) (revision d49a06fcbf63b36885b0d8f09a01f6539bcbfd56) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismResultView.cs (.../StabilityPointStructuresFailureMechanismResultView.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -26,6 +26,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 Ringtoets.StabilityPointStructures.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -37,6 +38,8 @@ /// public class StabilityPointStructuresFailureMechanismResultView : FailureMechanismResultView { + private const int assessmentLayerOneColumnIndex = 1; + private const int assessmentLayerTwoAIndex = 2; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; @@ -46,6 +49,7 @@ /// public StabilityPointStructuresFailureMechanismResultView() { + DataGridViewControl.AddCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. @@ -73,7 +77,9 @@ base.FailureMechanism = value; var calculatableFailureMechanism = value as ICalculatableFailureMechanism; - CalculationGroup observableGroup = calculatableFailureMechanism != null ? calculatableFailureMechanism.CalculationsGroup : null; + CalculationGroup observableGroup = calculatableFailureMechanism != null + ? calculatableFailureMechanism.CalculationsGroup + : null; calculationInputObserver.Observable = observableGroup; calculationOutputObserver.Observable = observableGroup; @@ -88,6 +94,7 @@ protected override void Dispose(bool disposing) { + DataGridViewControl.RemoveCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.RemoveCellFormattingHandler(DisableIrrelevantFieldsFormatting); calculationInputObserver.Dispose(); @@ -116,7 +123,7 @@ private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { - if (eventArgs.ColumnIndex > 1) + if (eventArgs.ColumnIndex > assessmentLayerOneColumnIndex) { if (HasPassedLevelOne(eventArgs.RowIndex)) { @@ -128,5 +135,22 @@ } } } + + private void ShowAssessmentLayerErrors(object sender, DataGridViewCellFormattingEventArgs e) + { + if (e.ColumnIndex != assessmentLayerTwoAIndex) + { + return; + } + + var resultRow = (StabilityPointStructuresFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); + 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/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -r01d9fa228242fbc40d96844c43b10dd281e3edbf -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismSectionResultRow.cs (.../StabilityPointStructuresFailureMechanismSectionResultRow.cs) (revision 01d9fa228242fbc40d96844c43b10dd281e3edbf) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/Views/StabilityPointStructuresFailureMechanismSectionResultRow.cs (.../StabilityPointStructuresFailureMechanismSectionResultRow.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -21,6 +21,7 @@ using System; using System.ComponentModel; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.StabilityPointStructures.Data; @@ -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/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -rc238c8de03e71e09a71c68b6f28fb057ef8a1c4d -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismResultViewTest.cs (.../StabilityPointStructuresFailureMechanismResultViewTest.cs) (revision c238c8de03e71e09a71c68b6f28fb057ef8a1c4d) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismResultViewTest.cs (.../StabilityPointStructuresFailureMechanismResultViewTest.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -28,7 +28,10 @@ using NUnit.Extensions.Forms; using NUnit.Framework; 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 Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.Views; @@ -76,21 +79,15 @@ // Setup using (StabilityPointStructuresFailureMechanismResultView view = CreateConfiguredFailureMechanismResultsView()) { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - var points = new[] - { - new Point2D(1, 2), - new Point2D(3, 4) - }; - - var section = new FailureMechanismSection("test", points); + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section); var testData = new List { sectionResult }; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + // Precondition Assert.AreEqual(2, dataGridView.RowCount); @@ -106,7 +103,7 @@ } [Test] - public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmtpy() + public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmpty() { // Setup var testData = new object(); @@ -153,6 +150,59 @@ } [Test] + [SetCulture("nl-NL")] + [TestCase(true)] + [TestCase(false)] + public void FailureMechanismResultsView_ChangeCheckBox_DataGridViewCorrectlySyncedAndStylingSet(bool checkBoxSelected) + { + // Setup + using (CreateConfiguredFailureMechanismResultsView()) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[assessmentLayerOneIndex].Value = checkBoxSelected; + + // Assert + var rows = dataGridView.Rows; + + var cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); + var cellAssessmentLayerTwoA = cells[assessmentLayerTwoAIndex]; + var cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; + DataGridViewCell dataGridViewCell = cells[assessmentLayerOneIndex]; + + Assert.AreEqual(checkBoxSelected, (bool) dataGridViewCell.FormattedValue); + Assert.AreEqual("-", cellAssessmentLayerTwoA.FormattedValue); + Assert.AreEqual("-", cellAssessmentLayerThree.FormattedValue); + Assert.IsEmpty(dataGridViewCell.ErrorText); + + var cellAssessmentLayerTwoABackColor = cellAssessmentLayerTwoA.Style.BackColor; + var cellAssessmentLayerTwoAForeColor = cellAssessmentLayerTwoA.Style.ForeColor; + var cellAssessmentLayerThreeBackColor = cellAssessmentLayerThree.Style.BackColor; + var cellAssessmentLayerThreeForeColor = cellAssessmentLayerThree.Style.ForeColor; + + if (checkBoxSelected) + { + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), cellAssessmentLayerTwoABackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), cellAssessmentLayerTwoAForeColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), cellAssessmentLayerThreeBackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), cellAssessmentLayerThreeForeColor); + } + else + { + Assert.AreEqual(Color.FromKnownColor(KnownColor.White), cellAssessmentLayerTwoABackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), cellAssessmentLayerTwoAForeColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.White), cellAssessmentLayerThreeBackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), cellAssessmentLayerThreeForeColor); + } + + Assert.AreEqual(checkBoxSelected, cellAssessmentLayerThree.ReadOnly); + } + } + + [Test] public void GivenFormWithFailureMechanismResultView_ThenExpectedColumnsAreVisible() { // Given @@ -285,14 +335,8 @@ public void GivenFormWithFailureMechanismResultView_WhenDataSourceWithOtherFailureMechanismSectionResultAssigned_ThenSectionsNotAdded() { // Given - var section1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0, 0) - }); - var section2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(0, 0) - }); + var section1 = CreateSimpleFailureMechanismSection(); + var section2 = CreateSimpleFailureMechanismSection(); var result1 = new TestFailureMechanismSectionResult(section1); var result2 = new TestFailureMechanismSectionResult(section2); @@ -312,6 +356,194 @@ } } + [Test] + public void GivenSectionResultWithoutCalculation_ThenLayerTwoAErrorTooltip() + { + // Given + using (StabilityPointStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(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 (StabilityPointStructuresFailureMechanismResultView view = ShowFailureMechanismResultsView()) + { + var calculation = new StructuresCalculation(); + FailureMechanismSection section = CreateSimpleFailureMechanismSection(); + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(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 (StabilityPointStructuresFailureMechanismResultView 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 StabilityPointStructuresFailureMechanismSectionResult(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 (StabilityPointStructuresFailureMechanismResultView 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 StabilityPointStructuresFailureMechanismSectionResult(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 (StabilityPointStructuresFailureMechanismResultView 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 StabilityPointStructuresFailureMechanismSectionResult(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/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rc238c8de03e71e09a71c68b6f28fb057ef8a1c4d -r4c6816a0272d6b38fb78d2d562b85248aa755e5d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismSectionResultRowTest.cs (.../StabilityPointStructuresFailureMechanismSectionResultRowTest.cs) (revision c238c8de03e71e09a71c68b6f28fb057ef8a1c4d) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresFailureMechanismSectionResultRowTest.cs (.../StabilityPointStructuresFailureMechanismSectionResultRowTest.cs) (revision 4c6816a0272d6b38fb78d2d562b85248aa755e5d) @@ -22,12 +22,14 @@ using Core.Common.Base.Geometry; using Core.Common.Utils.Reflection; using NUnit.Framework; +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 Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.Views; -using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.StabilityPointStructures.Forms.Test.Views { @@ -52,6 +54,116 @@ r => r.AssessmentLayerTwoA)); } + [Test] + public void AssessmentLayerTwoA_NoCalculationSet_ReturnNaN() + { + // Setup + FailureMechanismSection section = CreateSection(); + var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(sectionResult.Calculation); + + var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(result.Calculation); + + var row = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanismSectionResult(section) + { + Calculation = expectedCalculation + }; + + var row = new StabilityPointStructuresFailureMechanismSectionResultRow(result); + + // Call + StructuresCalculation calculation = row.GetSectionResultCalculation(); + + // Assert + Assert.AreSame(expectedCalculation, calculation); + } + private static FailureMechanismSection CreateSection() { return new FailureMechanismSection("name", new[]