Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs =================================================================== diff -u -r91b6773de2fccf52417609b4ed9463f98d6451dd -re5d2b62a6626e9d34433859f6dccfcf5a1eff783 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision 91b6773de2fccf52417609b4ed9463f98d6451dd) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismResultViewTest.cs (.../HeightStructuresFailureMechanismResultViewTest.cs) (revision e5d2b62a6626e9d34433859f6dccfcf5a1eff783) @@ -37,6 +37,7 @@ using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; +using Ringtoets.Common.Primitives; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.Views; @@ -140,33 +141,34 @@ DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual(SimpleAssessmentResultType.None, cells[assessmentLayerOneIndex].Value); Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); cells = rows[1].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual(SimpleAssessmentResultType.None, cells[assessmentLayerOneIndex].Value); Assert.AreEqual("-", cells[detailedAssessmentIndex].FormattedValue); Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); } } [Test] - [TestCase(AssessmentLayerOneState.NotAssessed)] - [TestCase(AssessmentLayerOneState.NoVerdict)] - [TestCase(AssessmentLayerOneState.Sufficient)] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] + [TestCase(SimpleAssessmentResultType.NotApplicable)] + [TestCase(SimpleAssessmentResultType.ProbabilityNegligible)] public void FailureMechanismResultsView_ChangeAssessmentLayerOneState_DataGridViewCorrectlySyncedAndStylingSet( - AssessmentLayerOneState assessmentLayerOneState) + SimpleAssessmentResultType simpleAssessmentResult) { // Setup using (CreateConfiguredFailureMechanismResultsView(new HeightStructuresFailureMechanism())) { var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Call - dataGridView.Rows[0].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + dataGridView.Rows[0].Cells[assessmentLayerOneIndex].Value = simpleAssessmentResult; // Assert DataGridViewRowCollection rows = dataGridView.Rows; @@ -178,12 +180,13 @@ DataGridViewCell cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; DataGridViewCell dataGridViewCell = cells[assessmentLayerOneIndex]; - Assert.AreEqual(assessmentLayerOneState, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual(simpleAssessmentResult, cells[assessmentLayerOneIndex].Value); Assert.AreEqual("-", detailedAssessmentCell.FormattedValue); Assert.AreEqual("-", cellAssessmentLayerThree.FormattedValue); Assert.IsEmpty(dataGridViewCell.ErrorText); - if (assessmentLayerOneState == AssessmentLayerOneState.Sufficient) + if (simpleAssessmentResult == SimpleAssessmentResultType.NotApplicable + || simpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible) { DataGridViewTestHelper.AssertCellIsDisabled(detailedAssessmentCell); DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerThree); @@ -201,6 +204,191 @@ } [Test] + public void FailureMechanismResultView_WithHeightStructuresFailureMechanismSectionResultAssigned_SectionsAddedAsRows() + { + // Setup + var section1 = new FailureMechanismSection("Section 1", new[] + { + new Point2D(0, 0) + }); + var section2 = new FailureMechanismSection("Section 2", new[] + { + new Point2D(0, 0) + }); + var section3 = new FailureMechanismSection("Section 3", new[] + { + new Point2D(0, 0) + }); + var section4 = new FailureMechanismSection("Section 4", new[] + { + new Point2D(0, 0) + }); + + var random = new Random(21); + var result1 = new HeightStructuresFailureMechanismSectionResult(section1) + { + SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, + AssessmentLayerThree = random.NextRoundedDouble() + }; + var result2 = new HeightStructuresFailureMechanismSectionResult(section2) + { + SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, + AssessmentLayerThree = random.NextRoundedDouble() + }; + var result3 = new HeightStructuresFailureMechanismSectionResult(section3) + { + SimpleAssessmentResult = SimpleAssessmentResultType.None, + AssessmentLayerThree = random.NextRoundedDouble() + }; + var result4 = new HeightStructuresFailureMechanismSectionResult(section4) + { + SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther, + AssessmentLayerThree = random.NextRoundedDouble() + }; + + // Call + using (ShowFailureMechanismResultsView(new ObservableList + { + result1, + result2, + result3, + result4 + })) + { + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(4, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(result1.SimpleAssessmentResult, cells[assessmentLayerOneIndex].Value); + + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(result1.AssessmentLayerThree), + cells[assessmentLayerThreeIndex].FormattedValue); + + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); + + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(result2.SimpleAssessmentResult, cells[assessmentLayerOneIndex].Value); + + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(result1.AssessmentLayerThree), + cells[assessmentLayerThreeIndex].FormattedValue); + + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); + + cells = rows[2].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 3", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(result3.SimpleAssessmentResult, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(result3.AssessmentLayerThree), + cells[assessmentLayerThreeIndex].FormattedValue); + + DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerTwoAIndex], true); + DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerThreeIndex]); + + cells = rows[3].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 4", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(result4.SimpleAssessmentResult, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(result4.AssessmentLayerThree), + cells[assessmentLayerThreeIndex].FormattedValue); + + DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerTwoAIndex], true); + DataGridViewTestHelper.AssertCellIsEnabled(cells[assessmentLayerThreeIndex]); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None, TestName = "FormWithFailureMechanismResultView_WhenSectionBecomesNotApplicableAndListenersNotified_RowsForSectionDisabled(None)")] + [TestCase(SimpleAssessmentResultType.AssessFurther, TestName = "FormWithFailureMechanismResultView_WhenSectionBecomesNotApplicableAndListenersNotified_RowsForSectionDisabled(AssessFurther)")] + public void GivenFormWithFailureMechanismResultView_WhenSectionBecomesNotApplicableAndListenersNotified_ThenRowsForSectionDisabled( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Given + var section = new FailureMechanismSection("Section 1", new[] + { + new Point2D(0, 0) + }); + var random = new Random(21); + var result = new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult, + AssessmentLayerThree = random.NextRoundedDouble() + }; + + using (ShowFailureMechanismResultsView(new ObservableList + { + result + })) + { + // When + result.SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable; + result.NotifyObservers(); + + // Then + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(1, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); + } + } + + [Test] + [TestCase(SimpleAssessmentResultType.None, TestName = "FormWithFailureMechanismResultView_WhenSectionBecomesProbabilityNegligibleAndListenersNotified_RowsForSectionDisabled(None)")] + [TestCase(SimpleAssessmentResultType.AssessFurther, TestName = "FormWithFailureMechanismResultView_WhenSectionBecomesProbabilityNegligibleAndListenersNotified_RowsForSectionDisabled(AssessFurther)")] + public void GivenFormWithFailureMechanismResultView_WhenSectionBecomesProbabilityNegligibleAndListenersNotified_ThenRowsForSectionDisabled( + SimpleAssessmentResultType simpleAssessmentResult) + { + // Given + var section = new FailureMechanismSection("Section 1", new[] + { + new Point2D(0, 0) + }); + var random = new Random(21); + var result = new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult, + AssessmentLayerThree = random.NextRoundedDouble() + }; + + using (ShowFailureMechanismResultsView(new ObservableList + { + result + })) + { + // When + result.SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable; + result.NotifyObservers(); + + // Then + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(1, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerTwoAIndex]); + DataGridViewTestHelper.AssertCellIsDisabled(cells[assessmentLayerThreeIndex]); + } + } + + [Test] [TestCase("test", assessmentLayerThreeIndex)] [TestCase(";/[].,~!@#$%^&*()_-+={}|?", assessmentLayerThreeIndex)] public void FailureMechanismResultView_EditValueInvalid_ShowsErrorTooltip(string newValue, int cellIndex) @@ -264,14 +452,14 @@ } [Test] - [TestCase(AssessmentLayerOneState.NotAssessed)] - [TestCase(AssessmentLayerOneState.NoVerdict)] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] public void GivenSectionResultWithoutCalculation_ThenDetailedAssessmentErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given var sectionResult = new HeightStructuresFailureMechanismSectionResult(CreateSimpleFailureMechanismSection()) { - AssessmentLayerOne = assessmentLayerOneState + SimpleAssessmentResult = simpleAssessmentResult }; using (ShowFailureMechanismResultsView( new ObservableList @@ -294,15 +482,15 @@ } [Test] - [TestCase(AssessmentLayerOneState.NotAssessed)] - [TestCase(AssessmentLayerOneState.NoVerdict)] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] public void GivenSectionResultAndCalculationNotCalculated_ThenDetailedAssessmentErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given var sectionResult = new HeightStructuresFailureMechanismSectionResult(CreateSimpleFailureMechanismSection()) { Calculation = new StructuresCalculation(), - AssessmentLayerOne = assessmentLayerOneState + SimpleAssessmentResult = simpleAssessmentResult }; using (ShowFailureMechanismResultsView( @@ -326,8 +514,8 @@ } [Test] - [TestCase(AssessmentLayerOneState.NotAssessed)] - [TestCase(AssessmentLayerOneState.NoVerdict)] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] public void GivenSectionResultAndFailedCalculation_ThenDetailedAssessmentErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) { // Given @@ -339,7 +527,7 @@ var sectionResult = new HeightStructuresFailureMechanismSectionResult(section) { Calculation = calculation, - AssessmentLayerOne = assessmentLayerOneState + SimpleAssessmentResult = simpleAssessmentResult }; using (ShowFailureMechanismResultsView( @@ -363,8 +551,8 @@ } [Test] - [TestCase(AssessmentLayerOneState.NotAssessed)] - [TestCase(AssessmentLayerOneState.NoVerdict)] + [TestCase(SimpleAssessmentResultType.None)] + [TestCase(SimpleAssessmentResultType.AssessFurther)] public void GivenSectionResultAndSuccessfulCalculation_ThenDetailedAssessmentNoError(AssessmentLayerOneState assessmentLayerOneState) { // Given @@ -374,7 +562,7 @@ { Output = new TestStructuresOutput(0.56789) }, - AssessmentLayerOne = assessmentLayerOneState + SimpleAssessmentResult = simpleAssessmentResult }; using (ShowFailureMechanismResultsView( @@ -398,8 +586,8 @@ } [Test] - [TestCaseSource(nameof(AssessmentLayerOneStateIsSufficientVariousSections))] - public void GivenSectionResultAndAssessmentLayerOneStateSufficient_ThenDetailedAssessmentNoError( + [TestCaseSource(nameof(GetVariousSimpleAssessmentResultConfigurationsWithoutErrorMessage))] + public void GivenVariousSectionResultAndSimpleAssessmentResultConfigurations_ThenDetailedAssessmentNoError( HeightStructuresFailureMechanismSectionResult sectionResult, string expectedValue) { // Given @@ -467,46 +655,70 @@ } } - private static IEnumerable AssessmentLayerOneStateIsSufficientVariousSections() + private static IEnumerable GetVariousSimpleAssessmentResultConfigurationsWithoutErrorMessage() { FailureMechanismSection section = CreateSimpleFailureMechanismSection(); yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) { - AssessmentLayerOne = AssessmentLayerOneState.Sufficient - }, "-").SetName("SectionWithoutCalculation"); + SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible + }, "-").SetName("SectionWithoutCalculationAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) { - AssessmentLayerOne = AssessmentLayerOneState.Sufficient, + SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = new StructuresCalculation() - }, "-").SetName("SectionWithCalculationNoOutput"); + }, "-").SetName("SectionWithCalculationNoOutputAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) { - AssessmentLayerOne = AssessmentLayerOneState.Sufficient, + SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = new StructuresCalculation { Output = new TestStructuresOutput(double.NaN) } - }, "-").SetName("SectionWithInvalidCalculationOutput"); + }, "-").SetName("SectionWithInvalidCalculationOutputAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) { - AssessmentLayerOne = AssessmentLayerOneState.Sufficient, + SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = new StructuresCalculation { Output = new TestStructuresOutput(0.56789) } - }, ProbabilityFormattingHelper.Format(0.25)).SetName("SectionWithValidCalculationOutput"); + }, ProbabilityFormattingHelper.Format(0.25)).SetName("SectionWithValidCalculationOutputAndSimpleAssessmentResultProbabilityNegligible"); + + yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable + }, "-").SetName("SectionWithoutCalculationAndSimpleAssessmentResultNotApplicable"); + yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, + Calculation = new StructuresCalculation() + }, "-").SetName("SectionWithCalculationNoOutputAndSimpleAssessmentResultNotApplicable"); + yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, + Calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(double.NaN) + } + }, "-").SetName("SectionWithInvalidCalculationOutputAndSimpleAssessmentResultNotApplicable"); + yield return new TestCaseData(new HeightStructuresFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, + Calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(0.56789) + } + }, ProbabilityFormattingHelper.Format(0.25)).SetName("SectionWithValidCalculationOutputAndSimpleAssessmentResultNotApplicable"); } private static FailureMechanismSection CreateSimpleFailureMechanismSection() { - var section = new FailureMechanismSection("A", - new[] - { - new Point2D(1, 2), - new Point2D(3, 4) - }); - return section; + return FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); } private HeightStructuresFailureMechanismResultView CreateConfiguredFailureMechanismResultsView(HeightStructuresFailureMechanism failureMechanism)