Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs =================================================================== diff -u -rc743d1f229ff553fff9a05964c1adac6e510df4a -r8e9fe7a143bba19aacde920aedd2101683479e60 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs (.../DuneLocationsViewTest.cs) (revision c743d1f229ff553fff9a05964c1adac6e510df4a) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Views/DuneLocationsViewTest.cs (.../DuneLocationsViewTest.cs) (revision 8e9fe7a143bba19aacde920aedd2101683479e60) @@ -38,7 +38,6 @@ using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service.TestUtil; using Ringtoets.DuneErosion.Data; -using Ringtoets.DuneErosion.Data.TestUtil; using Ringtoets.DuneErosion.Forms.GuiServices; using Ringtoets.DuneErosion.Forms.Views; using Ringtoets.HydraRing.Calculation.Calculator.Factory; @@ -84,43 +83,23 @@ // Call TestDelegate call = () => new DuneLocationsView(null, - dl => new DuneLocationCalculation(new TestDuneLocation()), new DuneErosionFailureMechanism(), assessmentSection); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("locations", exception.ParamName); + Assert.AreEqual("calculations", exception.ParamName); } [Test] - public void Constructor_GetCalculationFuncNull_ThrowsArgumentNullException() - { - // Setup - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - TestDelegate call = () => new DuneLocationsView(new ObservableList(), - null, - new DuneErosionFailureMechanism(), - assessmentSection); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("getCalculationFunc", exception.ParamName); - } - - [Test] public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call - TestDelegate call = () => new DuneLocationsView(new ObservableList(), - dl => new DuneLocationCalculation(new TestDuneLocation()), + TestDelegate call = () => new DuneLocationsView(new ObservableList(), null, assessmentSection); @@ -133,8 +112,7 @@ public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Call - TestDelegate call = () => new DuneLocationsView(new ObservableList(), - dl => new DuneLocationCalculation(new TestDuneLocation()), + TestDelegate call = () => new DuneLocationsView(new ObservableList(), new DuneErosionFailureMechanism(), null); @@ -153,8 +131,7 @@ var failureMechanism = new DuneErosionFailureMechanism(); // Call - using (var view = new DuneLocationsView(new ObservableList(), - dl => new DuneLocationCalculation(new TestDuneLocation()), + using (var view = new DuneLocationsView(new ObservableList(), failureMechanism, assessmentSection)) { @@ -174,7 +151,9 @@ mocks.ReplayAll(); // Call - DuneLocationsView view = ShowDuneLocationsView(new DuneErosionFailureMechanism(), assessmentSection); + DuneLocationsView view = ShowDuneLocationsView(new ObservableList(), + new DuneErosionFailureMechanism(), + assessmentSection); // Assert var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; @@ -266,8 +245,7 @@ mocks.ReplayAll(); // Call - using (var view = new DuneLocationsView(new ObservableList(), - dl => new DuneLocationCalculation(new TestDuneLocation()), + using (var view = new DuneLocationsView(new ObservableList(), new DuneErosionFailureMechanism(), assessmentSection)) { @@ -277,126 +255,125 @@ } [Test] - public void Selection_WithSelectedLocation_ReturnsSelectedLocationWrappedInContext() + public void Selection_WithSelectedCalculation_ReturnsSelectedLocationWrappedInContext() { // Setup var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection); + using (DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection)) + { + var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; + DataGridViewRow selectedLocationRow = dataGridView.Rows[0]; - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - DataGridViewRow selectedLocationRow = dataGridView.Rows[0]; + // Call + selectedLocationRow.Cells[0].Value = true; - // Call - selectedLocationRow.Cells[0].Value = true; + // Assert + var selection = view.Selection as DuneLocationCalculation; + var dataBoundItem = selectedLocationRow.DataBoundItem as DuneLocationRow; - // Assert - var selection = view.Selection as DuneLocation; - var dataBoundItem = selectedLocationRow.DataBoundItem as DuneLocationRow; - - Assert.NotNull(selection); - Assert.NotNull(dataBoundItem); - Assert.AreSame(dataBoundItem.CalculatableObject, selection); + Assert.NotNull(selection); + Assert.NotNull(dataBoundItem); + Assert.AreSame(dataBoundItem.CalculatableObject, selection); + } } [Test] - public void GivenFullyConfiguredDuneLocationsView_WhenDuneLocationsUpdatedAndNotified_ThenDataGridViewRowCorrectlyUpdated() + public void GivenFullyConfiguredDuneLocationsView_WhenDuneLocationCalculationsUpdatedAndNotified_ThenDataGridCorrectlyUpdated() { // Given var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection); - ObservableList locations = view.FailureMechanism.DuneLocations; - - // Precondition - var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true)[0]; - object originalDataSource = dataGridView.DataSource; - DataGridViewRowCollection rows = dataGridView.Rows; - rows[0].Cells[locationCalculateColumnIndex].Value = true; - Assert.AreEqual(2, rows.Count); - - // When - var duneLocation = new DuneLocation(10, "10", new Point2D(10.0, 10.0), new DuneLocation.ConstructionProperties + var calculations = new ObservableList(); + using (DuneLocationsView view = ShowDuneLocationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection)) { - CoastalAreaId = 3, - Offset = 80, - D50 = 0.000321 - }) - { - Calculation = + // 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 }) - } - }; - locations.Clear(); - locations.Add(duneLocation); - locations.NotifyObservers(); + }; + 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), - 0.000321.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), + 0.000321.ToString(CultureInfo.CurrentCulture) + }; + DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRowValues, rows[0]); + } } [Test] - public void GivenFullyConfiguredDuneLocationsView_WhenEachDuneLocationOutputClearedAndNotified_ThenDataGridViewRowsRefreshedWithNewValues() + public void GivenFullyConfiguredDuneLocationsView_WhenEachDuneLocationCalculationOutputClearedAndNotified_ThenDataGridViewRowsRefreshedWithNewValues() { // Given var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - DuneLocationsView view = ShowFullyConfiguredDuneLocationsView(assessmentSection); - ObservableList locations = view.FailureMechanism.DuneLocations; + ObservableList calculations = GenerateDuneLocationCalculations(); + using (DuneLocationsView 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]; - // 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); - 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(); + }); - // When - locations.ForEach(loc => - { - loc.Calculation.Output = null; - loc.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); + // 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] @@ -668,47 +645,20 @@ private DuneLocationsView ShowFullyConfiguredDuneLocationsView(IAssessmentSection assessmentSection) { - var locations = new ObservableList - { - new DuneLocation(1, "1", new Point2D(1.0, 1.0), new DuneLocation.ConstructionProperties - { - CoastalAreaId = 50, - Offset = 320, - D50 = 0.000837 - }), - new DuneLocation(2, "2", new Point2D(2.0, 2.0), new DuneLocation.ConstructionProperties - { - CoastalAreaId = 60, - Offset = 230, - D50 = 0.000123 - }) - { - Calculation = - { - Output = new DuneLocationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationOutput.ConstructionProperties - { - WaterLevel = 1.23, - WaveHeight = 2.34, - WavePeriod = 3.45 - }) - } - } - }; - var failureMechanism = new DuneErosionFailureMechanism { Contribution = 10 }; - failureMechanism.DuneLocations.AddRange(locations); - DuneLocationsView view = ShowDuneLocationsView(failureMechanism, assessmentSection); + DuneLocationsView view = ShowDuneLocationsView(GenerateDuneLocationCalculations(), failureMechanism, assessmentSection); return view; } - private DuneLocationsView ShowDuneLocationsView(DuneErosionFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + private DuneLocationsView ShowDuneLocationsView(IObservableEnumerable calculations, + DuneErosionFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) { - var view = new DuneLocationsView(failureMechanism.DuneLocations, - dl => dl.Calculation, + var view = new DuneLocationsView(calculations, failureMechanism, assessmentSection); @@ -717,5 +667,33 @@ 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