Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs =================================================================== diff -u -r9d7a5bd6246ec71a14f1944516d21e06954243f7 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision 9d7a5bd6246ec71a14f1944516d21e06954243f7) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -52,7 +52,11 @@ { get { - return assessmentLayerTwoA; + if (Calculation == null || !Calculation.HasOutput) + { + return double.NaN; + } + return Calculation.Output.Probability; } } Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rdf02e9274a94d8763da204833a4d93f984e242c6 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision df02e9274a94d8763da204833a4d93f984e242c6) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -425,6 +425,24 @@ } /// + /// Looks up a localized string similar to De maatgevende berekening voor dit vak is niet uitgevoerd.. + /// + public static string GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_calculated { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_calculated", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De maatgevende berekening voor dit vak heeft geen geldige uitkomst.. + /// + public static string GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_successful { + get { + return ResourceManager.GetString("GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_successful", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De parameter 'Fb' die gebruikt wordt in de berekening.. /// public static string GrassCoverErosionInwardsInput_FbFactor_Description { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx =================================================================== diff -u -rdf02e9274a94d8763da204833a4d93f984e242c6 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx (.../Resources.resx) (revision df02e9274a94d8763da204833a4d93f984e242c6) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/Resources.resx (.../Resources.resx) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -301,4 +301,10 @@ Golfhoogte (Hs) [-] + + De maatgevende berekening voor dit vak is niet uitgevoerd. + + + De maatgevende berekening voor dit vak heeft geen geldige uitkomst. + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs =================================================================== diff -u -rfa2a0dff6598123689fc7a69745440215879a243 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision fa2a0dff6598123689fc7a69745440215879a243) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -21,12 +21,16 @@ using System.Linq; using System.Windows.Forms; + using Core.Common.Base; using Core.Common.Utils.Reflection; + using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Views; using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Forms.Properties; + using CoreCommonResources = Core.Common.Base.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -40,35 +44,37 @@ private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; + private const int assessmentLayerTwoAIndex = 2; /// /// Creates a new instance of . /// public GrassCoverErosionInwardsFailureMechanismResultView() { + DataGridViewControl.AddCellFormattingHandler(ShowAssementLayerTwoAErrors); DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver( - UpdateDataGridViewDataSource, + UpdateDataGridViewDataSource, cg => cg.Children.Concat( cg.Children - .OfType() - .Select(c => c.GetObservableInput()) - ) - ); + .OfType() + .Select(c => c.GetObservableInput()) + ) + ); calculationOutputObserver = new RecursiveObserver( - UpdateDataGridViewDataSource, + UpdateDataGridViewDataSource, cg => cg.Children.Concat( cg.Children - .OfType() - .Select(c => c.GetObservableOutput()) - ) - ); + .OfType() + .Select(c => c.GetObservableOutput()) + ) + ); calculationGroupObserver = new RecursiveObserver( - UpdateDataGridViewDataSource, + UpdateDataGridViewDataSource, c => c.Children - ); + ); AddDataGridColumns(); } @@ -90,6 +96,7 @@ protected override void Dispose(bool disposing) { + DataGridViewControl.RemoveCellFormattingHandler(ShowAssementLayerTwoAErrors); DataGridViewControl.RemoveCellFormattingHandler(DisableIrrelevantFieldsFormatting); calculationInputObserver.Dispose(); @@ -99,33 +106,29 @@ base.Dispose(disposing); } + protected override object CreateFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) + { + return new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); + } + private void AddDataGridColumns() { DataGridViewControl.AddTextBoxColumn( - TypeUtils.GetMemberName(sr => sr.Name), - RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Section_name, - true - ); + TypeUtils.GetMemberName(sr => sr.Name), + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Section_name, + true); DataGridViewControl.AddCheckBoxColumn( - TypeUtils.GetMemberName(sr => sr.AssessmentLayerOne), - RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one - ); + TypeUtils.GetMemberName(sr => sr.AssessmentLayerOne), + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one); DataGridViewControl.AddTextBoxColumn( TypeUtils.GetMemberName(sr => sr.AssessmentLayerTwoA), RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - true - ); + true); DataGridViewControl.AddTextBoxColumn( TypeUtils.GetMemberName(sr => sr.AssessmentLayerThree), - RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three - ); + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } - protected override object CreateFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) - { - return new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); - } - private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > 1) @@ -140,5 +143,53 @@ } } } + + private void ShowAssementLayerTwoAErrors(object sender, DataGridViewCellFormattingEventArgs e) + { + if (e.ColumnIndex <= 0) + { + return; + } + + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + + var resultRow = (GrassCoverErosionInwardsFailureMechanismSectionResultRow)GetDataAtRow(e.RowIndex); + if (resultRow != null && e.ColumnIndex == assessmentLayerTwoAIndex) + { + GrassCoverErosionInwardsCalculation normativeCalculation = resultRow.GetSectionResultCalculation(); + + if (resultRow.AssessmentLayerOne || normativeCalculation == null) + { + currentDataGridViewCell.ErrorText = string.Empty; + return; + } + + CalculationScenarioStatus calculationScenarioStatus = GetCalculationStatus(normativeCalculation); + if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) + { + currentDataGridViewCell.ErrorText = Resources.GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_calculated; + return; + } + if (calculationScenarioStatus == CalculationScenarioStatus.Failed) + { + currentDataGridViewCell.ErrorText = Resources.GrassCoverErosionInwardsFailureMechanismResultView_Calculation_not_successful; + return; + } + currentDataGridViewCell.ErrorText = string.Empty; + } + } + + private static CalculationScenarioStatus GetCalculationStatus(GrassCoverErosionInwardsCalculation calculation) + { + if (calculation.HasOutput) + { + if (double.IsNaN(calculation.Output.Probability)) + { + return CalculationScenarioStatus.Failed; + } + return CalculationScenarioStatus.Done; + } + return CalculationScenarioStatus.NotCalculated; + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -r9d7a5bd6246ec71a14f1944516d21e06954243f7 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 9d7a5bd6246ec71a14f1944516d21e06954243f7) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -25,6 +25,7 @@ using Core.Common.Base.Data; using Ringtoets.Common.Forms.TypeConverters; + using Ringtoets.GrassCoverErosionInwards.Data; namespace Ringtoets.GrassCoverErosionInwards.Forms.Views @@ -107,5 +108,16 @@ sectionResult.AssessmentLayerThree = value; } } + + /// + /// 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 GrassCoverErosionInwardsCalculation GetSectionResultCalculation() + { + return sectionResult.Calculation; + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsSectionResultRow.cs =================================================================== diff -u -r9cdb6d4d4471994cf95246aab1409e54bbef8d1e -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsSectionResultRow.cs (.../GrassCoverErosionInwardsSectionResultRow.cs) (revision 9cdb6d4d4471994cf95246aab1409e54bbef8d1e) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsSectionResultRow.cs (.../GrassCoverErosionInwardsSectionResultRow.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -70,6 +70,7 @@ set { sectionResult.Calculation = value; + sectionResult.NotifyObservers(); } } } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs =================================================================== diff -u -rce94b8228bc7e51779b3754217580f13cb35e475 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision ce94b8228bc7e51779b3754217580f13cb35e475) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -20,10 +20,12 @@ // All rights reserved. using System; + using Core.Common.Base.Geometry; using Core.Common.Base.Storage; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; namespace Ringtoets.GrassCoverErosionInwards.Data.Test { @@ -54,10 +56,91 @@ Assert.IsInstanceOf(result); Assert.IsInstanceOf(result); Assert.AreSame(section, result.Section); + Assert.IsNull(result.Calculation); Assert.IsFalse(result.AssessmentLayerOne); Assert.IsNaN(result.AssessmentLayerTwoA); Assert.IsNaN(result.AssessmentLayerThree); Assert.AreEqual(0, result.StorageId); } + + [Test] + public void Calculation_SetNewValue_GetNewlySetValue() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + var calculation = new GrassCoverErosionInwardsCalculation(); + + // Call + result.Calculation = calculation; + + // Assert + Assert.AreSame(calculation, result.Calculation); + } + + [Test] + public void AssessmentLayerTwoA_CalculationNull_ReturnZero() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = null + }; + + // Call + double twoAValue = result.AssessmentLayerTwoA; + + // Assert + Assert.IsNaN(twoAValue); + } + + [Test] + public void AssessmentLayerTwoA_FailedCalculation_ReturnNaN() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(1.0, 1.0, double.NaN, 1.0, 1.0); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.0, false, probabilityAssessmentOutput) + } + }; + + // Call + double twoAValue = result.AssessmentLayerTwoA; + + // Assert + Assert.IsNaN(twoAValue); + } + + [Test] + public void AssessmentLayerTwoA_SuccessfulCalculation_ReturnInverseProbability() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + double probability = 0.65; + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(1.0, 1.0, probability, 1.0, 1.0); + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.0, false, probabilityAssessmentOutput) + } + }; + + // Call + double twoAValue = result.AssessmentLayerTwoA; + + // Assert + Assert.AreEqual(probability, twoAValue); + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj =================================================================== diff -u -r4e1b4ed200c6a9ad02e582e4596233188c64483f -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision 4e1b4ed200c6a9ad02e582e4596233188c64483f) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -78,6 +78,10 @@ {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data + + {4843d6e5-066f-4795-94f5-1d53932dd03c} + Ringtoets.Common.Data.TestUtil + {70f8cc9c-5bc8-4fb2-b201-eae7fa8088c2} Ringtoets.HydraRing.Data Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs =================================================================== diff -u -rce94b8228bc7e51779b3754217580f13cb35e475 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision ce94b8228bc7e51779b3754217580f13cb35e475) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -29,6 +29,8 @@ using NUnit.Extensions.Forms; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.Views; @@ -292,6 +294,212 @@ } } + [Test] + public void GivenSectionResultWithoutCalculation_ThenLayerTwoANoError() + { + // Setup + using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + { + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // Call + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("-", formattedValue); + Assert.IsEmpty(dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndCalculationNotCalculated_ThenLayerTwoAErrorTooltip() + { + // Setup + using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + { + var calculation = new GrassCoverErosionInwardsCalculation(); + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // Call + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak is niet uitgevoerd.", dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndFailedCalculation_ThenLayerTwoAErrorTooltip() + { + // Setup + using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + { + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(1.0, 1.0, double.NaN, 1.0, 1.0); + var calculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.0, false, probabilityAssessmentOutput) + }; + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // Call + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak heeft geen geldige uitkomst.", dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndSuccessfulCalculation_ThenLayerTwoANoError() + { + // Setup + using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + { + const double probability = 0.56789; + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(1.0, 1.0, probability, 1.0, 1.0); + var calculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.1, true, probabilityAssessmentOutput) + }; + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = calculation + }; + + view.Data = new[] + { + sectionResult + }; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[assessmentLayerTwoAIndex]; + + // Call + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual(ProbabilityFormattingHelper.Format(probability), formattedValue); + Assert.IsEmpty(dataGridViewCell.ErrorText); + } + } + + [Test] + public void GivenSectionResultAndSuccessfulCalculation_WhenCalculation_ThenLayerTwoANoError() + { + // Setup + using (var view = ShowFullyConfiguredFailureMechanismResultsView()) + { + const double probability = 0.56789; + var successfulCalculationOutput = new ProbabilityAssessmentOutput(1.0, 1.0, probability, 1.0, 1.0); + var successfulCalculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.1, true, successfulCalculationOutput) + }; + + var failedCalculationOutput = new ProbabilityAssessmentOutput(1.0, 1.0, double.NaN, 1.0, 1.0); + var failedCalculation = new GrassCoverErosionInwardsCalculation + { + Output = new GrassCoverErosionInwardsOutput(1.1, true, failedCalculationOutput) + }; + var section = new FailureMechanismSection("A", + new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(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); + + // Call + sectionResult.Calculation = failedCalculation; + formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("-", formattedValue); + Assert.AreEqual("De maatgevende berekening voor dit vak heeft geen geldige uitkomst.", dataGridViewCell.ErrorText); + } + } + private const int nameColumnIndex = 0; private const int assessmentLayerOneIndex = 1; private const int assessmentLayerTwoAIndex = 2; Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r9d7a5bd6246ec71a14f1944516d21e06954243f7 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 9d7a5bd6246ec71a14f1944516d21e06954243f7) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -29,7 +29,9 @@ using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.GrassCoverErosionInwards.Data; @@ -64,7 +66,6 @@ // Assert Assert.AreEqual(section.Name, row.Name); Assert.AreEqual(result.AssessmentLayerOne, row.AssessmentLayerOne); - Assert.AreEqual(result.AssessmentLayerTwoA, row.AssessmentLayerTwoA); Assert.AreEqual(result.AssessmentLayerThree, row.AssessmentLayerThree); Assert.IsTrue(TypeUtils.HasTypeConverter(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var section = new FailureMechanismSection("haha", new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }); + var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + sectionResult.Attach(observer); + + var row = new GrassCoverErosionInwardsSectionResultRow(sectionResult); + + var calculation = new GrassCoverErosionInwardsCalculation(); + + // Call + row.Calculation = calculation; + + // Assert + mocks.VerifyAll(); // Assert observer is notified + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs =================================================================== diff -u -rfa2a0dff6598123689fc7a69745440215879a243 -r8bb257bcf65291ebc7fc3b913d73bb11f40124d4 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision fa2a0dff6598123689fc7a69745440215879a243) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision 8bb257bcf65291ebc7fc3b913d73bb11f40124d4) @@ -22,12 +22,15 @@ using System; using System.Linq; using System.Windows.Forms; + using Core.Common.Base; using Core.Common.Utils.Reflection; + using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Views; using Ringtoets.Piping.Data; + using CoreCommonResources = Core.Common.Base.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -88,37 +91,33 @@ base.Dispose(disposing); } + protected override object CreateFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) + { + if (FailureMechanism == null) + { + return null; + } + return new PipingFailureMechanismSectionResultRow(sectionResult, FailureMechanism.Calculations.OfType()); + } + private void AddDataGridColumns() { DataGridViewControl.AddTextBoxColumn( TypeUtils.GetMemberName(sr => sr.Name), RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Section_name, - true - ); + true); DataGridViewControl.AddCheckBoxColumn( TypeUtils.GetMemberName(sr => sr.AssessmentLayerOne), - RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one - ); + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one); DataGridViewControl.AddTextBoxColumn( TypeUtils.GetMemberName(sr => sr.AssessmentLayerTwoA), RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - true - ); + true); DataGridViewControl.AddTextBoxColumn( TypeUtils.GetMemberName(sr => sr.AssessmentLayerThree), - RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three - ); + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } - protected override object CreateFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) - { - if (FailureMechanism == null) - { - return null; - } - return new PipingFailureMechanismSectionResultRow(sectionResult, FailureMechanism.Calculations.OfType()); - } - #region Event handling private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) @@ -142,11 +141,11 @@ { return; } - + var currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); - - PipingFailureMechanismSectionResultRow resultRow = (PipingFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); + PipingFailureMechanismSectionResultRow resultRow = (PipingFailureMechanismSectionResultRow)GetDataAtRow(e.RowIndex); + if (resultRow != null && e.ColumnIndex == assessmentLayerTwoAIndex) { PipingFailureMechanismSectionResult rowObject = resultRow.SectionResult; @@ -167,19 +166,16 @@ } var calculationScenarioStatus = rowObject.GetCalculationScenarioStatus(FailureMechanism.Calculations.OfType()); - if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) { currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_are_executed; return; } - if (calculationScenarioStatus == CalculationScenarioStatus.Failed) { currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_valid_output; return; } - currentDataGridViewCell.ErrorText = string.Empty; } }