Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj
===================================================================
diff -u -rdc532d6d17803dd8d323f7aa1f9fc95c691ae64e -r97db62926ec7858d3d2305e71559a0453f8feb21
--- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision dc532d6d17803dd8d323f7aa1f9fc95c691ae64e)
+++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -42,11 +42,11 @@
-
+
UserControl
-
- DuneLocationsView.cs
+
+ DuneLocationCalculationsView.cs
UserControl
Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.Designer.cs
===================================================================
diff -u
--- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.Designer.cs (revision 0)
+++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.Designer.cs (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -0,0 +1,45 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+namespace Ringtoets.DuneErosion.Forms.Views
+{
+ partial class DuneLocationCalculationsView
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ }
+
+ #endregion
+ }
+}
Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs
===================================================================
diff -u
--- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs (revision 0)
+++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationCalculationsView.cs (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -0,0 +1,183 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.DuneErosion.Data;
+using Ringtoets.DuneErosion.Forms.GuiServices;
+using Ringtoets.DuneErosion.Forms.Properties;
+using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
+
+namespace Ringtoets.DuneErosion.Forms.Views
+{
+ ///
+ /// View for the .
+ ///
+ public partial class DuneLocationCalculationsView : DuneLocationsViewBase
+ {
+ private readonly Observer duneLocationsObserver;
+ private readonly Observer failureMechanismObserver;
+ private readonly IObservableEnumerable calculations;
+ private readonly RecursiveObserver, DuneLocationCalculation> duneLocationObserver;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The calculations to show in the view
+ /// The failure mechanism which the calculations belong to.
+ /// The assessment section which the calculations belong to.
+ /// Thrown when any parameter is null.
+ public DuneLocationCalculationsView(IObservableEnumerable calculations,
+ DuneErosionFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ if (calculations == null)
+ {
+ throw new ArgumentNullException(nameof(calculations));
+ }
+
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ InitializeComponent();
+
+ this.calculations = calculations;
+ FailureMechanism = failureMechanism;
+ AssessmentSection = assessmentSection;
+
+ duneLocationsObserver = new Observer(UpdateDataGridViewDataSource)
+ {
+ Observable = calculations
+ };
+ duneLocationObserver = new RecursiveObserver, DuneLocationCalculation>(dataGridViewControl.RefreshDataGridView, list => list)
+ {
+ Observable = calculations
+ };
+ failureMechanismObserver = new Observer(UpdateCalculateForSelectedButton)
+ {
+ Observable = failureMechanism
+ };
+
+ UpdateDataGridViewDataSource();
+ }
+
+ public override object Data { get; set; }
+
+ ///
+ /// Gets the assessment section.
+ ///
+ public IAssessmentSection AssessmentSection { get; }
+
+ ///
+ /// Gets the for which the
+ /// locations are shown.
+ ///
+ public DuneErosionFailureMechanism FailureMechanism { get; }
+
+ ///
+ /// Gets or sets the
+ /// to perform calculations with.
+ ///
+ public DuneLocationCalculationGuiService CalculationGuiService { get; set; }
+
+ protected override void Dispose(bool disposing)
+ {
+ duneLocationsObserver.Dispose();
+ duneLocationObserver.Dispose();
+ failureMechanismObserver.Dispose();
+
+ base.Dispose(disposing);
+ }
+
+ protected override void InitializeDataGridView()
+ {
+ base.InitializeDataGridView();
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.Name),
+ RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Name_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.Id),
+ RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Id_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.Location),
+ RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Coordinates_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.CoastalAreaId),
+ Resources.DuneLocation_CoastalAreaId_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.Offset),
+ Resources.DuneLocation_Offset_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.WaterLevel),
+ Resources.DuneLocation_WaterLevel_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.WaveHeight),
+ Resources.DuneLocation_WaveHeight_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.WavePeriod),
+ Resources.DuneLocation_WavePeriod_DisplayName);
+ dataGridViewControl.AddTextBoxColumn(nameof(DuneLocationCalculationRow.D50),
+ Resources.DuneLocation_D50_DisplayName);
+ }
+
+ protected override object CreateSelectedItemFromCurrentRow()
+ {
+ DataGridViewRow currentRow = dataGridViewControl.CurrentRow;
+ return ((DuneLocationCalculationRow) currentRow?.DataBoundItem)?.CalculatableObject;
+ }
+
+ protected override void SetDataSource()
+ {
+ dataGridViewControl.SetDataSource(calculations?.Select(calc => new DuneLocationCalculationRow(calc)).ToArray());
+ }
+
+ protected override void CalculateForSelectedRows()
+ {
+ if (CalculationGuiService != null)
+ {
+ IEnumerable selectedCalculations = GetSelectedCalculatableObjects();
+ HandleCalculateSelectedLocations(selectedCalculations);
+ }
+ }
+
+ protected override string ValidateCalculatableObjects()
+ {
+ if (FailureMechanism != null && FailureMechanism.Contribution <= 0)
+ {
+ return RingtoetsCommonFormsResources.Contribution_of_failure_mechanism_zero;
+ }
+
+ return base.ValidateCalculatableObjects();
+ }
+
+ private void HandleCalculateSelectedLocations(IEnumerable calculations)
+ {
+ CalculationGuiService.Calculate(calculations,
+ AssessmentSection.HydraulicBoundaryDatabase.FilePath,
+ AssessmentSection.HydraulicBoundaryDatabase.EffectivePreprocessorDirectory(),
+ FailureMechanism.GetMechanismSpecificNorm(AssessmentSection.FailureMechanismContribution.Norm));
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 97db62926ec7858d3d2305e71559a0453f8feb21 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.Designer.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 97db62926ec7858d3d2305e71559a0453f8feb21 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Views/DuneLocationsView.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs
===================================================================
diff -u -rf0d6c65c6d7251bdc0c2cde6128d5777cff9ed49 -r97db62926ec7858d3d2305e71559a0453f8feb21
--- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision f0d6c65c6d7251bdc0c2cde6128d5777cff9ed49)
+++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -124,14 +124,13 @@
AdditionalDataCheck = context => context.WrappedData.IsRelevant
};
- yield return new ViewInfo, DuneLocationsView>
+ yield return new ViewInfo, DuneLocationCalculationsView>
{
GetViewName = (view, context) => RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName,
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
GetViewData = context => context.WrappedData,
CloseForData = CloseDuneLocationsViewForData,
- CreateInstance = context => new DuneLocationsView(context.WrappedData,
- dl => dl.Calculation,
+ CreateInstance = context => new DuneLocationCalculationsView(context.WrappedData,
context.FailureMechanism,
context.AssessmentSection),
AfterCreate = (view, context) => { view.CalculationGuiService = duneLocationCalculationGuiService; },
@@ -349,7 +348,7 @@
#region DuneLocationsView ViewInfo
- private static bool CloseDuneLocationsViewForData(DuneLocationsView view, object dataToCloseFor)
+ private static bool CloseDuneLocationsViewForData(DuneLocationCalculationsView view, object dataToCloseFor)
{
var failureMechanismContext = dataToCloseFor as DuneErosionFailureMechanismContext;
var assessmentSection = dataToCloseFor as IAssessmentSection;
Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs
===================================================================
diff -u
--- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs (revision 0)
+++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -0,0 +1,709 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
+using Core.Common.Util;
+using Core.Common.Util.Reflection;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.Common.Service.TestUtil;
+using Ringtoets.DuneErosion.Data;
+using Ringtoets.DuneErosion.Forms.GuiServices;
+using Ringtoets.DuneErosion.Forms.Views;
+using Ringtoets.HydraRing.Calculation.Calculator.Factory;
+using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics;
+using Ringtoets.HydraRing.Calculation.TestUtil.Calculator;
+
+namespace Ringtoets.DuneErosion.Forms.Test.Views
+{
+ [TestFixture]
+ public class DuneLocationCalculationsViewTest
+ {
+ private const int locationCalculateColumnIndex = 0;
+ private const int waterLevelColumnIndex = 6;
+ private const int waveHeightColumnIndex = 7;
+ private const int wavePeriodColumnIndex = 8;
+
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter");
+ private static readonly string validPreprocessorDirectory = TestHelper.GetScratchPadPath();
+
+ private Form testForm;
+ private MockRepository mocks;
+
+ [SetUp]
+ public void Setup()
+ {
+ testForm = new Form();
+ mocks = new MockRepository();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ testForm.Dispose();
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_LocationsNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => new DuneLocationCalculationsView(null,
+ new DuneErosionFailureMechanism(),
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("calculations", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => new DuneLocationCalculationsView(new ObservableList(),
+ null,
+ assessmentSection);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("failureMechanism", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new DuneLocationCalculationsView(new ObservableList(),
+ new DuneErosionFailureMechanism(),
+ null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var failureMechanism = new DuneErosionFailureMechanism();
+
+ // Call
+ using (var view = new DuneLocationCalculationsView(new ObservableList(),
+ failureMechanism,
+ assessmentSection))
+ {
+ // Assert
+ Assert.IsInstanceOf(view);
+ Assert.IsNull(view.Data);
+ Assert.AreSame(failureMechanism, view.FailureMechanism);
+ Assert.AreSame(assessmentSection, view.AssessmentSection);
+ }
+ }
+
+ [Test]
+ public void OnLoad_DataGridViewCorrectlyInitialized()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ DuneLocationCalculationsView view = ShowDuneLocationsView(new ObservableList(),
+ new DuneErosionFailureMechanism(),
+ assessmentSection);
+
+ // Assert
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+
+ var expectedHeaderNames = new[]
+ {
+ "Berekenen",
+ "Naam",
+ "ID",
+ "Coördinaten [m]",
+ "Kustvaknummer",
+ "Metrering [dam]",
+ "Rekenwaarde waterstand [m+NAP]",
+ "Rekenwaarde Hs [m]",
+ "Rekenwaarde Tp [s]",
+ "Rekenwaarde d50 [m]"
+ };
+ DataGridViewTestHelper.AssertExpectedHeaders(expectedHeaderNames, dataGridView);
+ var expectedColumnTypes = new[]
+ {
+ typeof(DataGridViewCheckBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn),
+ typeof(DataGridViewTextBoxColumn)
+ };
+ DataGridViewTestHelper.AssertColumnTypes(expectedColumnTypes, dataGridView);
+
+ var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0];
+ Assert.IsFalse(button.Enabled);
+ }
+
+ [Test]
+ public void DuneLocationsView_DataSet_DataGridViewCorrectlyInitialized()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection);
+
+ // Assert
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ Assert.AreEqual(2, rows.Count);
+
+ var expectedRow0Values = new object[]
+ {
+ false,
+ "1",
+ "1",
+ new Point2D(1, 1).ToString(),
+ "50",
+ "320",
+ "-",
+ "-",
+ "-",
+ 0.000837.ToString(CultureInfo.CurrentCulture)
+ };
+ DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow0Values, rows[0]);
+
+ var expectedRow1Values = new object[]
+ {
+ false,
+ "2",
+ "2",
+ new Point2D(2, 2).ToString(),
+ "60",
+ "230",
+ 1.23.ToString(CultureInfo.CurrentCulture),
+ 2.34.ToString(CultureInfo.CurrentCulture),
+ 3.45.ToString(CultureInfo.CurrentCulture),
+ 0.000123.ToString(CultureInfo.CurrentCulture)
+ };
+ DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow1Values, rows[1]);
+ }
+
+ [Test]
+ public void Selection_WithoutLocations_ReturnsNull()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ using (var view = new DuneLocationCalculationsView(new ObservableList(),
+ new DuneErosionFailureMechanism(),
+ assessmentSection))
+ {
+ // Assert
+ Assert.IsNull(view.Selection);
+ }
+ }
+
+ [Test]
+ public void Selection_WithSelectedCalculation_ReturnsSelectedLocationWrappedInContext()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRow selectedLocationRow = dataGridView.Rows[0];
+
+ // Call
+ selectedLocationRow.Cells[0].Value = true;
+
+ // Assert
+ var selection = view.Selection as DuneLocationCalculation;
+ var dataBoundItem = selectedLocationRow.DataBoundItem as DuneLocationCalculationRow;
+
+ Assert.NotNull(selection);
+ Assert.NotNull(dataBoundItem);
+ Assert.AreSame(dataBoundItem.CalculatableObject, selection);
+ }
+ }
+
+ [Test]
+ public void GivenFullyConfiguredDuneLocationsView_WhenDuneLocationCalculationsUpdatedAndNotified_ThenDataGridCorrectlyUpdated()
+ {
+ // Given
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ var calculations = new ObservableList();
+ using (DuneLocationCalculationsView view = ShowDuneLocationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection))
+ {
+ // Precondition
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ object originalDataSource = dataGridView.DataSource;
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ Assert.AreEqual(0, rows.Count);
+
+ // When
+ var duneLocation = new DuneLocation(10, "10", new Point2D(10.0, 10.0), new DuneLocation.ConstructionProperties
+ {
+ CoastalAreaId = 3,
+ Offset = 80,
+ D50 = 0.000321
+ });
+ var duneLocationCalculation = new DuneLocationCalculation(duneLocation)
+ {
+ Output = new DuneLocationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationOutput.ConstructionProperties
+ {
+ WaterLevel = 3.21,
+ WaveHeight = 4.32,
+ WavePeriod = 5.43
+ })
+ };
+ calculations.Add(duneLocationCalculation);
+ calculations.NotifyObservers();
+
+ // Then
+ Assert.AreNotSame(originalDataSource, dataGridView.DataSource);
+
+ var expectedRowValues = new object[]
+ {
+ false,
+ "10",
+ "10",
+ new Point2D(10, 10).ToString(),
+ "3",
+ "80",
+ 3.21.ToString(CultureInfo.CurrentCulture),
+ 4.32.ToString(CultureInfo.CurrentCulture),
+ 5.43.ToString(CultureInfo.CurrentCulture),
+ 0.000321.ToString(CultureInfo.CurrentCulture)
+ };
+ DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRowValues, rows[0]);
+ }
+ }
+
+ [Test]
+ public void GivenFullyConfiguredDuneLocationsView_WhenEachDuneLocationCalculationOutputClearedAndNotified_ThenDataGridViewRowsRefreshedWithNewValues()
+ {
+ // Given
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ ObservableList calculations = GenerateDuneLocationCalculations();
+ using (DuneLocationCalculationsView view = ShowDuneLocationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection))
+ {
+ // Precondition
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ Assert.AreEqual(2, rows.Count);
+ DataGridViewRow firstRow = rows[0];
+ DataGridViewRow secondRow = rows[1];
+
+ Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue);
+ Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue);
+ Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue);
+ Assert.AreEqual(1.23.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waterLevelColumnIndex].FormattedValue);
+ Assert.AreEqual(2.34.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waveHeightColumnIndex].FormattedValue);
+ Assert.AreEqual(3.45.ToString(CultureInfo.CurrentCulture), secondRow.Cells[wavePeriodColumnIndex].FormattedValue);
+
+ // When
+ calculations.ForEach(calculation =>
+ {
+ calculation.Output = null;
+ calculation.NotifyObservers();
+ });
+
+ // Then
+ Assert.AreEqual(2, rows.Count);
+ Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue);
+ Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue);
+ Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue);
+ Assert.AreEqual("-", secondRow.Cells[waterLevelColumnIndex].FormattedValue);
+ Assert.AreEqual("-", secondRow.Cells[waveHeightColumnIndex].FormattedValue);
+ Assert.AreEqual("-", secondRow.Cells[wavePeriodColumnIndex].FormattedValue);
+ }
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndKeepOriginalSelection()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ assessmentSection.Stub(a => a.Id).Return("1");
+ assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
+ assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
+ {
+ FilePath = Path.Combine(testDataPath, "complete.sqlite")
+ });
+ assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
+ assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();
+
+ var calculationsObserver = mocks.StrictMock();
+
+ var calculatorFactory = mocks.StrictMock();
+ calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath, string.Empty))
+ .Return(new TestDunesBoundaryConditionsCalculator());
+ mocks.ReplayAll();
+
+ ObservableList calculations = GenerateDuneLocationCalculations();
+ var failureMechanism = new DuneErosionFailureMechanism
+ {
+ Contribution = 10
+ };
+ using (DuneLocationCalculationsView view = ShowDuneLocationsView(calculations, failureMechanism, assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ object originalDataSource = dataGridView.DataSource;
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+
+ calculations.Attach(calculationsObserver);
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ using (var viewParent = new Form())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
+ {
+ view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);
+
+ // Call
+ Action action = () => buttonTester.Click();
+
+ // Assert
+ TestHelper.AssertLogMessages(action,
+ messages =>
+ {
+ List messageList = messages.ToList();
+
+ // Assert
+ Assert.AreEqual(8, messageList.Count);
+ Assert.AreEqual("Hydraulische randvoorwaarden berekenen voor locatie '1' is gestart.", messageList[0]);
+ CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
+ CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
+ CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
+ Assert.AreEqual("Hydraulische randvoorwaarden berekening voor locatie '1' is niet geconvergeerd.", messageList[4]);
+ StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", messageList[5]);
+ CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]);
+ Assert.AreEqual("Hydraulische randvoorwaarden berekenen voor locatie '1' is gelukt.", messageList[7]);
+ });
+
+ Assert.AreSame(originalDataSource, dataGridView.DataSource);
+
+ Assert.IsTrue((bool) rows[0].Cells[locationCalculateColumnIndex].Value);
+ Assert.IsFalse((bool) rows[1].Cells[locationCalculateColumnIndex].Value);
+ }
+ }
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+
+ var button = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ // Call
+ TestDelegate test = () => button.Click();
+
+ // Assert
+ Assert.DoesNotThrow(test);
+ }
+ }
+
+ [Test]
+ [TestCase(false, true, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_RowSelectionContributionSet_SyncedAccordingly(false, false, message)")]
+ [TestCase(true, true, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_RowSelectionContributionSet_SyncedAccordingly(true, false, message)")]
+ [TestCase(false, false, "Er zijn geen berekeningen geselecteerd.", TestName = "CalculateButton_RowSelectionContributionSet_SyncedAccordingly(false, true, message)")]
+ [TestCase(true, false, "", TestName = "CalculateButton_RowSelectionContributionSet_SyncedAccordingly(true, true, message)")]
+ public void GivenDuneLocationsView_WhenSpecificCombinationOfRowSelectionAndFailureMechanismContributionSet_ThenButtonAndErrorMessageSyncedAccordingly(bool rowSelected,
+ bool contributionZero,
+ string expectedErrorMessage)
+ {
+ // Given
+ var assessmentSection = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ // When
+ if (rowSelected)
+ {
+ var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+ }
+
+ if (contributionZero)
+ {
+ view.FailureMechanism.Contribution = 0;
+ view.FailureMechanism.NotifyObservers();
+ }
+
+ // Then
+ var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0];
+ Assert.AreEqual(rowSelected && !contributionZero, button.Enabled);
+ var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider");
+ Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button));
+ }
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_HydraulicBoundaryDatabaseWithCanUsePreprocessorFalse_CreateDunesBoundaryConditionsCalculatorCalledAsExpected()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ assessmentSection.Stub(a => a.Id).Return("1");
+ assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
+ assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
+ {
+ FilePath = Path.Combine(testDataPath, "complete.sqlite")
+ });
+ assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
+ assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();
+
+ var calculatorFactory = mocks.StrictMock();
+ var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator();
+ calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath, string.Empty))
+ .Return(dunesBoundaryConditionsCalculator);
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ using (var viewParent = new Form())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
+ {
+ view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);
+
+ // Call
+ buttonTester.Click();
+
+ // Assert
+ DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = dunesBoundaryConditionsCalculator.ReceivedInputs.First();
+
+ Assert.AreEqual(1, dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
+ double expectedProbability = view.FailureMechanism.GetMechanismSpecificNorm(assessmentSection.FailureMechanismContribution.Norm);
+ Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(expectedProbability), dunesBoundaryConditionsCalculationInput.Beta);
+ }
+ }
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_HydraulicBoundaryDatabaseWithUsePreprocessorTrue_CreateDunesBoundaryConditionsCalculatorCalledAsExpected()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ assessmentSection.Stub(a => a.Id).Return("1");
+ assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
+ assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
+ {
+ FilePath = Path.Combine(testDataPath, "complete.sqlite"),
+ CanUsePreprocessor = true,
+ UsePreprocessor = true,
+ PreprocessorDirectory = validPreprocessorDirectory
+ });
+ assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
+ assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();
+
+ var calculatorFactory = mocks.StrictMock();
+ var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator();
+ calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath, validPreprocessorDirectory))
+ .Return(dunesBoundaryConditionsCalculator);
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ using (var viewParent = new Form())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
+ {
+ view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);
+
+ // Call
+ buttonTester.Click();
+
+ // Assert
+ DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = dunesBoundaryConditionsCalculator.ReceivedInputs.First();
+
+ Assert.AreEqual(1, dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
+ double expectedProbability = view.FailureMechanism.GetMechanismSpecificNorm(assessmentSection.FailureMechanismContribution.Norm);
+ Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(expectedProbability), dunesBoundaryConditionsCalculationInput.Beta);
+ }
+ }
+ }
+
+ [Test]
+ public void CalculateForSelectedButton_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_CreateDunesBoundaryConditionsCalculatorCalledAsExpected()
+ {
+ // Setup
+ var assessmentSection = mocks.Stub();
+ assessmentSection.Stub(a => a.Id).Return("1");
+ assessmentSection.Stub(a => a.FailureMechanismContribution)
+ .Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
+
+ assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
+ {
+ FilePath = Path.Combine(testDataPath, "complete.sqlite"),
+ CanUsePreprocessor = true,
+ UsePreprocessor = false,
+ PreprocessorDirectory = "InvalidPreprocessorDirectory"
+ });
+ assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
+ assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();
+
+ var calculatorFactory = mocks.StrictMock();
+ var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator();
+ calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath, string.Empty))
+ .Return(dunesBoundaryConditionsCalculator);
+ mocks.ReplayAll();
+
+ using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection))
+ {
+ var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0];
+ DataGridViewRowCollection rows = dataGridView.Rows;
+ rows[0].Cells[locationCalculateColumnIndex].Value = true;
+
+ var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);
+
+ using (var viewParent = new Form())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
+ {
+ view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);
+
+ // Call
+ buttonTester.Click();
+
+ // Assert
+ DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = dunesBoundaryConditionsCalculator.ReceivedInputs.First();
+
+ Assert.AreEqual(1, dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
+ double expectedProbability = view.FailureMechanism.GetMechanismSpecificNorm(assessmentSection.FailureMechanismContribution.Norm);
+ Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(expectedProbability), dunesBoundaryConditionsCalculationInput.Beta);
+ }
+ }
+ }
+
+ private DuneLocationCalculationsView ShowFullyConfiguredDuneLocationsView(IAssessmentSection assessmentSection)
+ {
+ var failureMechanism = new DuneErosionFailureMechanism
+ {
+ Contribution = 10
+ };
+
+ DuneLocationCalculationsView view = ShowDuneLocationsView(GenerateDuneLocationCalculations(), failureMechanism, assessmentSection);
+ return view;
+ }
+
+ private DuneLocationCalculationsView ShowDuneLocationsView(IObservableEnumerable calculations,
+ DuneErosionFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
+ {
+ var view = new DuneLocationCalculationsView(calculations,
+ failureMechanism,
+ assessmentSection);
+
+ testForm.Controls.Add(view);
+ testForm.Show();
+
+ return view;
+ }
+
+ private static ObservableList GenerateDuneLocationCalculations()
+ {
+ var calculations = new ObservableList
+ {
+ new DuneLocationCalculation(new DuneLocation(1, "1", new Point2D(1.0, 1.0), new DuneLocation.ConstructionProperties
+ {
+ CoastalAreaId = 50,
+ Offset = 320,
+ D50 = 0.000837
+ })),
+ new DuneLocationCalculation(new DuneLocation(2, "2", new Point2D(2.0, 2.0), new DuneLocation.ConstructionProperties
+ {
+ CoastalAreaId = 60,
+ Offset = 230,
+ D50 = 0.000123
+ }))
+ {
+ Output = new DuneLocationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationOutput.ConstructionProperties
+ {
+ WaterLevel = 1.23,
+ WaveHeight = 2.34,
+ WavePeriod = 3.45
+ })
+ }
+ };
+ return calculations;
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 97db62926ec7858d3d2305e71559a0453f8feb21 refers to a dead (removed) revision in file `Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Integration.Test/DuneLocationsViewIntegrationTest.cs
===================================================================
diff -u -r8e9fe7a143bba19aacde920aedd2101683479e60 -r97db62926ec7858d3d2305e71559a0453f8feb21
--- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Integration.Test/DuneLocationsViewIntegrationTest.cs (.../DuneLocationsViewIntegrationTest.cs) (revision 8e9fe7a143bba19aacde920aedd2101683479e60)
+++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Integration.Test/DuneLocationsViewIntegrationTest.cs (.../DuneLocationsViewIntegrationTest.cs) (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -66,7 +66,7 @@
string expectedErrorMessage)
{
// Given
- DuneLocationsView view = ShowFullyConfiguredDuneLocationsView();
+ DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationsView();
if (rowSelected)
{
@@ -96,7 +96,7 @@
Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button));
}
- private DuneLocationsView ShowFullyConfiguredDuneLocationsView()
+ private DuneLocationCalculationsView ShowFullyConfiguredDuneLocationsView()
{
var calculations = new ObservableList
{
@@ -123,17 +123,17 @@
};
ObservableList generateDuneLocationCalculations = calculations;
- DuneLocationsView view = ShowDuneLocationsView(generateDuneLocationCalculations,
+ DuneLocationCalculationsView view = ShowDuneLocationsView(generateDuneLocationCalculations,
new DuneErosionFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
return view;
}
- private DuneLocationsView ShowDuneLocationsView(IObservableEnumerable calculations,
+ private DuneLocationCalculationsView ShowDuneLocationsView(IObservableEnumerable calculations,
DuneErosionFailureMechanism failureMechanism,
IAssessmentSection assessmentSection)
{
- var view = new DuneLocationsView(calculations,
+ var view = new DuneLocationCalculationsView(calculations,
failureMechanism,
assessmentSection);
Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs
===================================================================
diff -u -r1a1c79792a4f6e4ef9f79dce6017a0582f994559 -r97db62926ec7858d3d2305e71559a0453f8feb21
--- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision 1a1c79792a4f6e4ef9f79dce6017a0582f994559)
+++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Plugin.Test/DuneErosionPluginTest.cs (.../DuneErosionPluginTest.cs) (revision 97db62926ec7858d3d2305e71559a0453f8feb21)
@@ -135,7 +135,7 @@
viewInfos,
typeof(DuneLocationCalculationsContext),
typeof(IEnumerable),
- typeof(DuneLocationsView));
+ typeof(DuneLocationCalculationsView));
}
}