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);