Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -racb9db836c6b6cdd639842b4cb559cec5141ba8a -r3af4966b460f479dba1acd47805152617af8a77b --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision acb9db836c6b6cdd639842b4cb559cec5141ba8a) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Views/ClosingStructuresFailureMechanismResultViewTest.cs (.../ClosingStructuresFailureMechanismResultViewTest.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) @@ -46,7 +46,6 @@ private const int assessmentLayerOneIndex = 1; private const int assessmentLayerTwoAIndex = 2; private const int assessmentLayerThreeIndex = 3; - private Form testForm; [SetUp] @@ -156,6 +155,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 GivenFormWithClosingStructuresFailureMechanismResultView_ThenExpectedColumnsAreVisible() { // Given Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs =================================================================== diff -u -rd49a06fcbf63b36885b0d8f09a01f6539bcbfd56 -r3af4966b460f479dba1acd47805152617af8a77b --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision d49a06fcbf63b36885b0d8f09a01f6539bcbfd56) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) @@ -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.HeightStructures.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -37,6 +38,8 @@ /// public class HeightStructuresFailureMechanismResultView : 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 HeightStructuresFailureMechanismResultView() { + DataGridViewControl.AddCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. @@ -83,6 +87,7 @@ protected override void Dispose(bool disposing) { + DataGridViewControl.RemoveCellFormattingHandler(ShowAssessmentLayerErrors); DataGridViewControl.RemoveCellFormattingHandler(DisableIrrelevantFieldsFormatting); calculationInputObserver.Dispose(); @@ -117,7 +122,7 @@ private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { - if (eventArgs.ColumnIndex > 1) + if (eventArgs.ColumnIndex > assessmentLayerOneColumnIndex) { if (HasPassedLevelOne(eventArgs.RowIndex)) { @@ -129,5 +134,25 @@ } } } + + private void ShowAssessmentLayerErrors(object sender, DataGridViewCellFormattingEventArgs e) + { + if (e.ColumnIndex != assessmentLayerTwoAIndex) + { + return; + } + + var resultRow = (HeightStructuresFailureMechanismSectionResultRow) 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/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismSectionResultRow.cs =================================================================== diff -u -r673e35de0df920529e5dda63ea8b4dfb08ed65a8 -r3af4966b460f479dba1acd47805152617af8a77b --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismSectionResultRow.cs (.../HeightStructuresFailureMechanismSectionResultRow.cs) (revision 673e35de0df920529e5dda63ea8b4dfb08ed65a8) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismSectionResultRow.cs (.../HeightStructuresFailureMechanismSectionResultRow.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) @@ -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.HeightStructures.Data; @@ -50,5 +51,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/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -r3af4966b460f479dba1acd47805152617af8a77b --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) @@ -60,7 +60,7 @@ public void DefaultConstructor_DefaultValues() { // Call - using (var view = new HeightStructuresFailureMechanismResultView()) + using (HeightStructuresFailureMechanismResultView view = new HeightStructuresFailureMechanismResultView()) { // Assert Assert.IsInstanceOf>(view); @@ -127,11 +127,11 @@ } [Test] - public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmtpy() + public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewEmpty() { // Setup var testData = new object(); - using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + using (HeightStructuresFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView()) { var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; @@ -140,7 +140,6 @@ // Assert Assert.IsNull(view.Data); - Assert.AreEqual(0, dataGridView.RowCount); } } @@ -194,10 +193,12 @@ Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); var cellAssessmentLayerTwoA = cells[assessmentLayerTwoAIndex]; var cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; + DataGridViewCell dataGridViewCell = cells[assessmentLayerOneIndex]; - Assert.AreEqual(checkBoxSelected, (bool) cells[assessmentLayerOneIndex].FormattedValue); + 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; Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r673e35de0df920529e5dda63ea8b4dfb08ed65a8 -r3af4966b460f479dba1acd47805152617af8a77b --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismSectionResultRowTest.cs (.../HeightStructuresFailureMechanismSectionResultRowTest.cs) (revision 673e35de0df920529e5dda63ea8b4dfb08ed65a8) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismSectionResultRowTest.cs (.../HeightStructuresFailureMechanismSectionResultRowTest.cs) (revision 3af4966b460f479dba1acd47805152617af8a77b) @@ -22,7 +22,10 @@ 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.HeightStructures.Data; @@ -37,10 +40,7 @@ public void Constructor_WithParameters_ExpectedValues() { // Setup - var section = new FailureMechanismSection("name", new[] - { - new Point2D(0, 0) - }); + FailureMechanismSection section = CreateSection(); var result = new HeightStructuresFailureMechanismSectionResult(section); // Call @@ -53,5 +53,123 @@ FailureMechanismSectionResultNoProbabilityValueDoubleConverter>( r => r.AssessmentLayerTwoA)); } + + [Test] + public void AssessmentLayerTwoA_NoCalculationSet_ReturnNaN() + { + // Setup + FailureMechanismSection section = CreateSection(); + var sectionResult = new HeightStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(sectionResult.Calculation); + + var resultRow = new HeightStructuresFailureMechanismSectionResultRow(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 HeightStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new HeightStructuresFailureMechanismSectionResultRow(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 HeightStructuresFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + var resultRow = new HeightStructuresFailureMechanismSectionResultRow(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 HeightStructuresFailureMechanismSectionResult(section); + + // Precondition + Assert.IsNull(result.Calculation); + + var row = new HeightStructuresFailureMechanismSectionResultRow(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 HeightStructuresFailureMechanismSectionResult(section) + { + Calculation = expectedCalculation + }; + + var row = new HeightStructuresFailureMechanismSectionResultRow(result); + + // Call + StructuresCalculation calculation = row.GetSectionResultCalculation(); + + // Assert + Assert.AreSame(expectedCalculation, calculation); + } + + private static FailureMechanismSection CreateSection() + { + return new FailureMechanismSection("name", new[] + { + new Point2D(0, 0) + }); + } } } \ No newline at end of file