Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/HydraulicBoundaryCalculationsViewTest.cs =================================================================== diff -u -r2099f5c28f0980f31e91d886ae368b32006ec9a2 -rd2a807400c3b244cb82398baa044298918315967 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/HydraulicBoundaryCalculationsViewTest.cs (.../HydraulicBoundaryCalculationsViewTest.cs) (revision 2099f5c28f0980f31e91d886ae368b32006ec9a2) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/HydraulicBoundaryCalculationsViewTest.cs (.../HydraulicBoundaryCalculationsViewTest.cs) (revision d2a807400c3b244cb82398baa044298918315967) @@ -162,7 +162,7 @@ TestHydraulicBoundaryCalculationsView view = ShowTestHydraulicBoundaryCalculationsView(); // Assert - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; + Button button = GetCalculateForSelectedButton(view); Assert.IsFalse(button.Enabled); } @@ -173,7 +173,7 @@ ShowTestHydraulicBoundaryCalculationsView(); // Assert - CheckBox checkBox = GetSHowHydraulicBoundaryDatabaseFileNameCheckBox(); + CheckBox checkBox = GetShowHydraulicBoundaryDatabaseFileNameCheckBox(); Assert.AreEqual("Toon HRD bestand", checkBox.Text); Assert.IsFalse(checkBox.Checked); } @@ -344,7 +344,7 @@ TestHydraulicBoundaryCalculationsView view = ShowFullyConfiguredTestHydraulicBoundaryCalculationsView(); // Then - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; + Button button = GetCalculateForSelectedButton(view); Assert.IsFalse(button.Enabled); ErrorProvider errorProvider = GetErrorProvider(view); Assert.AreEqual("Er zijn geen berekeningen geselecteerd.", errorProvider.GetError(button)); @@ -361,7 +361,7 @@ dataGridView.Rows[0].Cells[calculateColumnIndex].Value = true; // Then - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; + Button button = GetCalculateForSelectedButton(view); Assert.IsTrue(button.Enabled); ErrorProvider errorProvider = GetErrorProvider(view); Assert.AreEqual("", errorProvider.GetError(button)); @@ -431,7 +431,7 @@ Assert.IsFalse(hydraulicBoundaryDatabaseFileNameColumn.Visible); // When - CheckBox checkBox = GetSHowHydraulicBoundaryDatabaseFileNameCheckBox(); + CheckBox checkBox = GetShowHydraulicBoundaryDatabaseFileNameCheckBox(); checkBox.Checked = true; // Then @@ -535,11 +535,16 @@ return TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); } - private CheckBox GetSHowHydraulicBoundaryDatabaseFileNameCheckBox() + private CheckBox GetShowHydraulicBoundaryDatabaseFileNameCheckBox() { return ControlTestHelper.GetControls(testForm, "showHydraulicBoundaryDatabaseFileNameColumnCheckBox").Single(); } + private Button GetCalculateForSelectedButton(TestHydraulicBoundaryCalculationsView view) + { + return (Button) view.Controls.Find("CalculateForSelectedButton", true).Single(); + } + private IllustrationPointsControl GetIllustrationPointsControl() { return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); Index: Riskeer/DuneErosion/test/Riskeer.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs =================================================================== diff -u -ra8862f6a2c03c22a430f2905efdf3c7ca4a3bf8e -rd2a807400c3b244cb82398baa044298918315967 --- Riskeer/DuneErosion/test/Riskeer.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs (.../DuneLocationCalculationsViewTest.cs) (revision a8862f6a2c03c22a430f2905efdf3c7ca4a3bf8e) +++ Riskeer/DuneErosion/test/Riskeer.DuneErosion.Forms.Test/Views/DuneLocationCalculationsViewTest.cs (.../DuneLocationCalculationsViewTest.cs) (revision d2a807400c3b244cb82398baa044298918315967) @@ -28,6 +28,7 @@ using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.TestUtil; using Core.Common.Util; @@ -40,6 +41,7 @@ using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; using Riskeer.Common.Service.TestUtil; using Riskeer.DuneErosion.Data; using Riskeer.DuneErosion.Forms.GuiServices; @@ -93,10 +95,10 @@ // Call void Call() => new DuneLocationCalculationsView(null, - new DuneErosionFailureMechanism(), - assessmentSection, - () => 0.01, - () => "1/100"); + new DuneErosionFailureMechanism(), + assessmentSection, + () => 0.01, + () => "1/100"); // Assert var exception = Assert.Throws(Call); @@ -112,10 +114,10 @@ // Call void Call() => new DuneLocationCalculationsView(new ObservableList(), - null, - assessmentSection, - () => 0.01, - () => "1/100"); + null, + assessmentSection, + () => 0.01, + () => "1/100"); // Assert var exception = Assert.Throws(Call); @@ -127,10 +129,10 @@ { // Call void Call() => new DuneLocationCalculationsView(new ObservableList(), - new DuneErosionFailureMechanism(), - null, - () => 0.01, - () => "1/100"); + new DuneErosionFailureMechanism(), + null, + () => 0.01, + () => "1/100"); // Assert var exception = Assert.Throws(Call); @@ -146,31 +148,29 @@ // Call void Call() => new DuneLocationCalculationsView(new ObservableList(), - new DuneErosionFailureMechanism(), - assessmentSection, - null, - () => "1/100"); + new DuneErosionFailureMechanism(), + assessmentSection, + null, + () => "1/100"); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("getTargetProbabilityFunc", exception.ParamName); } [Test] - [TestCase(null)] - [TestCase("")] - public void Constructor_GetCalculationIdentifierFuncNull_ThrowsArgumentException(string calculationIdentifier) + public void Constructor_GetCalculationIdentifierFuncNull_ThrowsArgumentException() { // Setup var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call void Call() => new DuneLocationCalculationsView(new ObservableList(), - new DuneErosionFailureMechanism(), - assessmentSection, - () => 0.01, - null); + new DuneErosionFailureMechanism(), + assessmentSection, + () => 0.01, + null); // Assert var exception = Assert.Throws(Call); @@ -188,10 +188,10 @@ // Call using (var view = new DuneLocationCalculationsView(new ObservableList(), - failureMechanism, - assessmentSection, - () => 0.01, - () => "1/100")) + failureMechanism, + assessmentSection, + () => 0.01, + () => "1/100")) { // Assert Assert.IsInstanceOf(view); @@ -208,57 +208,55 @@ public void Constructor_CalculateAllButtonCorrectlyInitialized() { // Setup & Call - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView()) - { - // Assert - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; - Assert.IsFalse(button.Enabled); - } + DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(); + + // Assert + Button button = GetCalculateForSelectedButton(view); + Assert.IsFalse(button.Enabled); } [Test] public void Constructor_DataGridViewCorrectlyInitialized() { // Setup & Call - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView()) - { - // Assert - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; + ShowDuneLocationCalculationsView(); - var expectedHeaderNames = new[] - { - "Berekenen", - "Naam", - "ID", - "Coördinaten [m]", - "Kustvaknummer", - "Metrering [dam]", - "Rekenwaarde waterstand [m+NAP]", - "Rekenwaarde Hs [m]", - "Rekenwaarde Tp [s]", - "Rekenwaarde gemiddelde getijamplitude [m]", - "Rekenwaarde golfrichtingspreiding [-]", - "Rekenwaarde faseverschuiving tussen getij en opzet [uur]" - }; - DataGridViewTestHelper.AssertExpectedHeaders(expectedHeaderNames, dataGridView); + // Assert + DataGridView dataGridView = GetDataGridView(); - Type[] expectedColumnTypes = - { - typeof(DataGridViewCheckBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn), - typeof(DataGridViewTextBoxColumn) - }; - DataGridViewTestHelper.AssertColumnTypes(expectedColumnTypes, dataGridView); - } + var expectedHeaderNames = new[] + { + "Berekenen", + "Naam", + "ID", + "Coördinaten [m]", + "Kustvaknummer", + "Metrering [dam]", + "Rekenwaarde waterstand [m+NAP]", + "Rekenwaarde Hs [m]", + "Rekenwaarde Tp [s]", + "Rekenwaarde gemiddelde getijamplitude [m]", + "Rekenwaarde golfrichtingspreiding [-]", + "Rekenwaarde faseverschuiving tussen getij en opzet [uur]" + }; + DataGridViewTestHelper.AssertExpectedHeaders(expectedHeaderNames, dataGridView); + + Type[] expectedColumnTypes = + { + typeof(DataGridViewCheckBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn), + typeof(DataGridViewTextBoxColumn) + }; + DataGridViewTestHelper.AssertColumnTypes(expectedColumnTypes, dataGridView); } [Test] @@ -291,79 +289,77 @@ mocks.ReplayAll(); // Call - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, - hydraulicBoundaryLocation)) + ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, hydraulicBoundaryLocation); + + // Assert + var dataGridView = GetDataGridView(); + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + + var expectedRow0Values = new object[] { - // Assert - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRowCollection rows = dataGridView.Rows; - Assert.AreEqual(2, rows.Count); + false, + "1", + "0", + new Point2D(0, 0).ToString(), + "50", + "320", + "-", + "-", + "-", + "-", + "-", + "-" + }; + DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow0Values, rows[0]); - var expectedRow0Values = new object[] - { - false, - "1", - "0", - new Point2D(0, 0).ToString(), - "50", - "320", - "-", - "-", - "-", - "-", - "-", - "-" - }; - DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow0Values, rows[0]); + var expectedRow1Values = new object[] + { + false, + "2", + "0", + new Point2D(0, 0).ToString(), + "60", + "230", + 1.23.ToString(CultureInfo.CurrentCulture), + 2.34.ToString(CultureInfo.CurrentCulture), + 3.45.ToString(CultureInfo.CurrentCulture), + 4.35.ToString(CultureInfo.CurrentCulture), + 5.54.ToString(CultureInfo.CurrentCulture), + 6.45.ToString(CultureInfo.CurrentCulture) + }; + DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow1Values, rows[1]); + } - var expectedRow1Values = new object[] - { - false, - "2", - "0", - new Point2D(0, 0).ToString(), - "60", - "230", - 1.23.ToString(CultureInfo.CurrentCulture), - 2.34.ToString(CultureInfo.CurrentCulture), - 3.45.ToString(CultureInfo.CurrentCulture), - 4.35.ToString(CultureInfo.CurrentCulture), - 5.54.ToString(CultureInfo.CurrentCulture), - 6.45.ToString(CultureInfo.CurrentCulture) - }; - DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRow1Values, rows[1]); - } } [Test] public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedFired() { // Given - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView()) - { - var selectionChangedCount = 0; - view.SelectionChanged += (sender, args) => selectionChangedCount++; + DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(); - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; + var selectionChangedCount = 0; + view.SelectionChanged += (sender, args) => selectionChangedCount++; - // When - dataGridView.CurrentCell = dataGridView.Rows[1].Cells[calculateColumnIndex]; - EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0)); + var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - // Then - Assert.AreEqual(1, selectionChangedCount); - } + // When + dataGridView.CurrentCell = dataGridView.Rows[1].Cells[calculateColumnIndex]; + EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0)); + + // Then + Assert.AreEqual(1, selectionChangedCount); } [Test] public void Selection_WithoutCalculations_ReturnsNull() { // Call - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView()) - { - // Assert - Assert.IsNull(view.Selection); - } + DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(); + + // Assert + Assert.IsNull(view.Selection); } [Test] @@ -373,107 +369,102 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, - new TestHydraulicBoundaryLocation())) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRow selectedCalculationRow = dataGridView.Rows[0]; + DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, + new TestHydraulicBoundaryLocation()); - // Call - selectedCalculationRow.Cells[0].Value = true; + DataGridView dataGridView = GetDataGridView(); + DataGridViewRow selectedCalculationRow = dataGridView.Rows[0]; - // Assert - var selection = view.Selection as DuneLocationCalculation; - var dataBoundItem = selectedCalculationRow.DataBoundItem as DuneLocationCalculationRow; + // Call + selectedCalculationRow.Cells[0].Value = true; - Assert.NotNull(selection); - Assert.NotNull(dataBoundItem); - Assert.AreSame(dataBoundItem.CalculatableObject, selection); - } + // Assert + var selection = view.Selection as DuneLocationCalculation; + var dataBoundItem = selectedCalculationRow.DataBoundItem as DuneLocationCalculationRow; + + Assert.NotNull(selection); + Assert.NotNull(dataBoundItem); + Assert.AreSame(dataBoundItem.CalculatableObject, selection); } [Test] public void SelectAllButton_SelectAllButtonClicked_AllCalculationsSelected() { // Setup - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView()) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRowCollection rows = dataGridView.Rows; - var button = new ButtonTester("SelectAllButton", testForm); + ShowFullyConfiguredDuneLocationCalculationsView(); - // Precondition - Assert.IsFalse((bool) rows[0].Cells[calculateColumnIndex].Value); - Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); + DataGridView dataGridView = GetDataGridView(); + DataGridViewRowCollection rows = dataGridView.Rows; + var button = new ButtonTester("SelectAllButton", testForm); - // Call - button.Click(); + // Precondition + Assert.IsFalse((bool) rows[0].Cells[calculateColumnIndex].Value); + Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); - // Assert - Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); - Assert.IsTrue((bool) rows[1].Cells[calculateColumnIndex].Value); - } + // Call + button.Click(); + + // Assert + Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); + Assert.IsTrue((bool) rows[1].Cells[calculateColumnIndex].Value); } [Test] public void DeselectAllButton_AllCalculationsSelectedDeselectAllButtonClicked_AllCalculationsNotSelected() { // Setup - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView()) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - var button = new ButtonTester("DeselectAllButton", testForm); + ShowFullyConfiguredDuneLocationCalculationsView(); - DataGridViewRowCollection rows = dataGridView.Rows; - foreach (DataGridViewRow row in rows) - { - row.Cells[calculateColumnIndex].Value = true; - } + DataGridView dataGridView = GetDataGridView(); + var button = new ButtonTester("DeselectAllButton", testForm); - // Precondition - Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); - Assert.IsTrue((bool) rows[1].Cells[calculateColumnIndex].Value); + DataGridViewRowCollection rows = dataGridView.Rows; + foreach (DataGridViewRow row in rows) + { + row.Cells[calculateColumnIndex].Value = true; + } - // Call - button.Click(); + // Precondition + Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); + Assert.IsTrue((bool) rows[1].Cells[calculateColumnIndex].Value); - // Assert - Assert.IsFalse((bool) rows[0].Cells[calculateColumnIndex].Value); - Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); - } + // Call + button.Click(); + + // Assert + Assert.IsFalse((bool) rows[0].Cells[calculateColumnIndex].Value); + Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); } [Test] public void GivenFullyConfiguredView_WhenNoRowsSelected_ThenCalculateForSelectedButtonDisabledAndErrorMessageProvided() { // Given & When - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView()) - { - // Then - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; - Assert.IsFalse(button.Enabled); - var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); - Assert.AreEqual("Er zijn geen berekeningen geselecteerd.", errorProvider.GetError(button)); - } + DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(); + + // Then + Button button = GetCalculateForSelectedButton(view); + Assert.IsFalse(button.Enabled); + ErrorProvider errorProvider = GetErrorProvider(view); + Assert.AreEqual("Er zijn geen berekeningen geselecteerd.", errorProvider.GetError(button)); } [Test] public void GivenFullyConfiguredView_WhenRowsSelected_ThenCalculateForSelectedButtonEnabledAndNoErrorMessageProvided() { // Given - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView()) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; + DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(); - // When - dataGridView.Rows[0].Cells[calculateColumnIndex].Value = true; + DataGridView dataGridView = GetDataGridView(); - // Then - var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; - Assert.IsTrue(button.Enabled); - var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); - Assert.AreEqual("", errorProvider.GetError(button)); - } + // When + dataGridView.Rows[0].Cells[calculateColumnIndex].Value = true; + + // Then + Button button = GetCalculateForSelectedButton(view); + Assert.IsTrue(button.Enabled); + var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); + Assert.AreEqual("", errorProvider.GetError(button)); } [Test] @@ -484,61 +475,58 @@ mocks.ReplayAll(); var calculations = new ObservableList(); - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(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); + ShowDuneLocationCalculationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection); - // When - var duneLocation = new DuneLocation( - "10", new HydraulicBoundaryLocation(10, string.Empty, 10.0, 10.0), - new DuneLocation.ConstructionProperties - { - CoastalAreaId = 3, - Offset = 80 - }); - var duneLocationCalculation = new DuneLocationCalculation(duneLocation) + // Precondition + DataGridView dataGridView = GetDataGridView(); + object originalDataSource = dataGridView.DataSource; + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(0, rows.Count); + + // When + var duneLocation = new DuneLocation( + "10", new HydraulicBoundaryLocation(10, string.Empty, 10.0, 10.0), + new DuneLocation.ConstructionProperties { - Output = new DuneLocationCalculationOutput( - CalculationConvergence.CalculatedConverged, - new DuneLocationCalculationOutput.ConstructionProperties - { - WaterLevel = 3.21, - WaveHeight = 4.32, - WavePeriod = 5.43, - MeanTidalAmplitude = 4.35, - WaveDirectionalSpread = 5.54, - TideSurgePhaseDifference = 6.45 - }) - }; - calculations.Add(duneLocationCalculation); - calculations.NotifyObservers(); + CoastalAreaId = 3, + Offset = 80 + }); + var duneLocationCalculation = new DuneLocationCalculation(duneLocation) + { + Output = new DuneLocationCalculationOutput( + CalculationConvergence.CalculatedConverged, + new DuneLocationCalculationOutput.ConstructionProperties + { + WaterLevel = 3.21, + WaveHeight = 4.32, + WavePeriod = 5.43, + MeanTidalAmplitude = 4.35, + WaveDirectionalSpread = 5.54, + TideSurgePhaseDifference = 6.45 + }) + }; + calculations.Add(duneLocationCalculation); + calculations.NotifyObservers(); - // Then - Assert.AreNotSame(originalDataSource, dataGridView.DataSource); + // 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), - 4.35.ToString(CultureInfo.CurrentCulture), - 5.54.ToString(CultureInfo.CurrentCulture), - 6.45.ToString(CultureInfo.CurrentCulture) - }; - DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRowValues, rows[0]); - } + 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), + 4.35.ToString(CultureInfo.CurrentCulture), + 5.54.ToString(CultureInfo.CurrentCulture), + 6.45.ToString(CultureInfo.CurrentCulture) + }; + DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRowValues, rows[0]); } [Test] @@ -551,53 +539,50 @@ mocks.ReplayAll(); IObservableEnumerable calculations = GenerateDuneLocationCalculations(hydraulicBoundaryLocation); - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(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]; + ShowDuneLocationCalculationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection); - Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); + // Precondition + DataGridView dataGridView = GetDataGridView(); + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + DataGridViewRow firstRow = rows[0]; + DataGridViewRow secondRow = rows[1]; - 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); - Assert.AreEqual(4.35.ToString(CultureInfo.CurrentCulture), secondRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); - Assert.AreEqual(5.54.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); - Assert.AreEqual(6.45.ToString(CultureInfo.CurrentCulture), secondRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); - // When - calculations.ForEachElementDo(calculation => - { - calculation.Output = null; - calculation.NotifyObservers(); - }); + Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); - // 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("-", firstRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); - Assert.AreEqual("-", firstRow.Cells[tideSurgePhaseDifferenceColumnIndex].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); + Assert.AreEqual(4.35.ToString(CultureInfo.CurrentCulture), secondRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); + Assert.AreEqual(5.54.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); + Assert.AreEqual(6.45.ToString(CultureInfo.CurrentCulture), secondRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); + // When + calculations.ForEachElementDo(calculation => + { + calculation.Output = null; + calculation.NotifyObservers(); + }); - Assert.AreEqual("-", secondRow.Cells[waterLevelColumnIndex].FormattedValue); - Assert.AreEqual("-", secondRow.Cells[waveHeightColumnIndex].FormattedValue); - Assert.AreEqual("-", secondRow.Cells[wavePeriodColumnIndex].FormattedValue); - Assert.AreEqual("-", secondRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); - Assert.AreEqual("-", secondRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); - Assert.AreEqual("-", secondRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); - } + // 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("-", firstRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); + Assert.AreEqual("-", firstRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); + + Assert.AreEqual("-", secondRow.Cells[waterLevelColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[wavePeriodColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[meanTidalAmplitudeColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[waveDirectionalSpreadColumnIndex].FormattedValue); + Assert.AreEqual("-", secondRow.Cells[tideSurgePhaseDifferenceColumnIndex].FormattedValue); } [Test] @@ -642,36 +627,32 @@ mocks.ReplayAll(); IObservableEnumerable calculations = GenerateDuneLocationCalculations(hydraulicBoundaryLocation); - var failureMechanism = new DuneErosionFailureMechanism(); + DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection); - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations, - failureMechanism, - assessmentSection)) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - object originalDataSource = dataGridView.DataSource; - DataGridViewRowCollection rows = dataGridView.Rows; - rows[0].Cells[calculateColumnIndex].Value = true; + DataGridView dataGridView = GetDataGridView(); + object originalDataSource = dataGridView.DataSource; + DataGridViewRowCollection rows = dataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; - calculations.Attach(calculationsObserver); + calculations.Attach(calculationsObserver); - var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); - using (var viewParent = new TestViewParentForm()) - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) - { - view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent); + using (var viewParent = new TestViewParentForm()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent); - // Call - buttonTester.Click(); + // Call + buttonTester.Click(); - // Assert - Assert.AreSame(originalDataSource, dataGridView.DataSource); + // Assert + Assert.AreSame(originalDataSource, dataGridView.DataSource); - Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); - Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); - } - } } + Assert.IsTrue((bool) rows[0].Cells[calculateColumnIndex].Value); + Assert.IsFalse((bool) rows[1].Cells[calculateColumnIndex].Value); + } + } [Test] public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() @@ -680,21 +661,19 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - using (DuneLocationCalculationsView view = ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, - new TestHydraulicBoundaryLocation())) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRowCollection rows = dataGridView.Rows; - rows[0].Cells[calculateColumnIndex].Value = true; + ShowFullyConfiguredDuneLocationCalculationsView(assessmentSection, new TestHydraulicBoundaryLocation()); - var button = new ButtonTester("CalculateForSelectedButton", testForm); + DataGridView dataGridView = GetDataGridView(); + DataGridViewRowCollection rows = dataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; - // Call - void Call() => button.Click(); + var button = new ButtonTester("CalculateForSelectedButton", testForm); - // Assert - Assert.DoesNotThrow(Call); - } + // Call + void Call() => button.Click(); + + // Assert + Assert.DoesNotThrow(Call); } [Test] @@ -739,48 +718,43 @@ mocks.ReplayAll(); IObservableEnumerable calculations = GenerateDuneLocationCalculations(hydraulicBoundaryLocation); - var failureMechanism = new DuneErosionFailureMechanism(); + DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection); - using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations, - failureMechanism, - assessmentSection)) - { - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRowCollection rows = dataGridView.Rows; - rows[0].Cells[calculateColumnIndex].Value = true; + DataGridView dataGridView = GetDataGridView(); + DataGridViewRowCollection rows = dataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; - calculations.Attach(calculationsObserver); + calculations.Attach(calculationsObserver); - var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); - using (var viewParent = new TestViewParentForm()) - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) - { - view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent); + using (var viewParent = new TestViewParentForm()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent); - // Call - void Call() => buttonTester.Click(); + // Call + void Call() => buttonTester.Click(); - // Assert - string expectedDuneLocationName = calculations.ElementAt(0).DuneLocation.Name; + // Assert + string expectedDuneLocationName = calculations.ElementAt(0).DuneLocation.Name; - TestHelper.AssertLogMessages(Call, - messages => - { - List messageList = messages.ToList(); + TestHelper.AssertLogMessages(Call, + messages => + { + List messageList = messages.ToList(); - // Assert - Assert.AreEqual(8, messageList.Count); - Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gestart.", messageList[0]); - CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]); - CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); - Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{expectedDuneLocationName}' (1/100) is niet geconvergeerd.", messageList[4]); - StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[5]); - CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]); - Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gelukt.", messageList[7]); - }); - } + // Assert + Assert.AreEqual(8, messageList.Count); + Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gestart.", messageList[0]); + CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]); + CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]); + Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{expectedDuneLocationName}' (1/100) is niet geconvergeerd.", messageList[4]); + StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[5]); + CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]); + Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gelukt.", messageList[7]); + }); } } @@ -840,15 +814,15 @@ var failureMechanism = new DuneErosionFailureMechanism(); using (var view = new DuneLocationCalculationsView(duneLocationCalculations, - failureMechanism, - assessmentSection, - () => targetProbability, - () => "1/100")) + failureMechanism, + assessmentSection, + () => targetProbability, + () => "1/100")) { testForm.Controls.Add(view); testForm.Show(); - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; + DataGridView dataGridView = GetDataGridView(); DataGridViewRowCollection rows = dataGridView.Rows; rows[0].Cells[calculateColumnIndex].Value = true; @@ -871,6 +845,28 @@ } } + + private DataGridView GetDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "dataGridView"); + } + + private static ErrorProvider GetErrorProvider(DuneLocationCalculationsView view) + { + return TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); + } + + private Button GetCalculateForSelectedButton(DuneLocationCalculationsView view) + { + return (Button) view.Controls.Find("CalculateForSelectedButton", true).Single(); + } + + private DataGridViewControl GetDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private DuneLocationCalculationsView ShowFullyConfiguredDuneLocationCalculationsView() { var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); @@ -905,7 +901,7 @@ } private DuneLocationCalculationsView ShowFullyConfiguredDuneLocationCalculationsView(IAssessmentSection assessmentSection, - HydraulicBoundaryLocation hydraulicBoundaryLocation) + HydraulicBoundaryLocation hydraulicBoundaryLocation) { var failureMechanism = new DuneErosionFailureMechanism(); @@ -926,10 +922,10 @@ IAssessmentSection assessmentSection) { var view = new DuneLocationCalculationsView(calculations, - failureMechanism, - assessmentSection, - () => 0.01, - () => "1/100"); + failureMechanism, + assessmentSection, + () => 0.01, + () => "1/100"); testForm.Controls.Add(view); testForm.Show();