Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs =================================================================== diff -u -r304e242143c13dbe48d1c5d36ed3f8721ad85f60 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs (.../IllustrationPointsControlTest.cs) (revision 304e242143c13dbe48d1c5d36ed3f8721ad85f60) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs (.../IllustrationPointsControlTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -19,13 +19,13 @@ // 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.Data; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; -using NUnit.Extensions.Forms; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Data.TestUtil.IllustrationPoints; @@ -87,7 +87,7 @@ } [Test] - public void GivenFullyConfiguredControl_WhenSelectingCellInRow_ThenSelectionChangedFired() + public void GivenFullyConfiguredControl_WhenSelectingCellInSecondRow_ThenSelectionChangedFired() { // Given using (var form = new Form()) @@ -96,24 +96,14 @@ form.Controls.Add(control); form.Show(); - control.Data = new[] - { - new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(), - "SSE", - "Regular", - Enumerable.Empty(), - (RoundedDouble) 3.14) - }; + control.Data = GetIllustrationPointControlItems().ToArray(); var selectionChangedCount = 0; control.SelectionChanged += (sender, args) => selectionChangedCount++; - - IllustrationPointsTableControl tableControl = ControlTestHelper.GetControls(form, "IllustrationPointsTableControl").Single(); DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(form, "illustrationPointsDataGridViewControl"); - dataGridView.SetCurrentCell(dataGridView.Rows[0].Cells[0]); // When - EventHelper.RaiseEvent(tableControl, "SelectionChanged"); + dataGridView.SetCurrentCell(dataGridView.Rows[1].Cells[0]); // Then Assert.AreEqual(1, selectionChangedCount); @@ -130,29 +120,41 @@ form.Controls.Add(control); form.Show(); - control.Data = new[] - { - new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(), - "SSE", - "Regular", - Enumerable.Empty(), - (RoundedDouble) 3.14) - }; + control.Data = GetIllustrationPointControlItems().ToArray(); IllustrationPointsTableControl tableControl = ControlTestHelper.GetControls(form, "IllustrationPointsTableControl").Single(); DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(form, "illustrationPointsDataGridViewControl"); - DataGridViewRow selectedLocationRow = dataGridView.Rows[0]; + var initialControlSelection = control.Selection as IllustrationPointControlItem; + // Call - selectedLocationRow.Cells[0].Value = true; + dataGridView.SetCurrentCell(dataGridView.Rows[1].Cells[0]); // Assert var expectedSelection = tableControl.Selection as IllustrationPointControlItem; var controlSelection = control.Selection as IllustrationPointControlItem; Assert.IsNotNull(expectedSelection); Assert.IsNotNull(controlSelection); Assert.AreSame(expectedSelection, controlSelection); + + Assert.AreNotSame(initialControlSelection, controlSelection); } } + + private static IEnumerable GetIllustrationPointControlItems() + { + var random = new Random(7); + yield return new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(), + "SSE", + "Regular", + Enumerable.Empty(), + random.NextRoundedDouble()); + + yield return new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(), + "SSE", + "Different", + Enumerable.Empty(), + random.NextRoundedDouble()); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsTableControlTest.cs =================================================================== diff -u -r304e242143c13dbe48d1c5d36ed3f8721ad85f60 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsTableControlTest.cs (.../IllustrationPointsTableControlTest.cs) (revision 304e242143c13dbe48d1c5d36ed3f8721ad85f60) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsTableControlTest.cs (.../IllustrationPointsTableControlTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -232,21 +232,40 @@ } [Test] - public void Selection_WithIllustrationPoints_ReturnsSelectedIllustrationPointControlItem() + public void Selection_WithIllustrationPoints_ReturnsIllustrationPointControlItem() { // Setup IllustrationPointsTableControl control = ShowControl(); control.Data = GetControlItems(); - DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView"); - DataGridViewRow selectedLocationRow = dataGridView.Rows[0]; + DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(testForm, "illustrationPointsDataGridViewControl"); // Call - selectedLocationRow.Cells[0].Value = true; + var selection = control.Selection as IllustrationPointControlItem; // Assert + var dataBoundItem = dataGridView.Rows[0].DataBoundItem as IllustrationPointRow; + Assert.NotNull(selection); + Assert.NotNull(dataBoundItem); + Assert.AreSame(dataBoundItem.IllustrationPointControlItem, selection); + } + + [Test] + public void GivenControlWithIllustrationPoints_WhenSelectingSecondRow_ThenSelectionReturnsIllustrationPointControlItem() + { + // Given + IllustrationPointsTableControl control = ShowControl(); + control.Data = GetControlItems(); + + DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(testForm, "illustrationPointsDataGridViewControl"); + + // When + DataGridViewRow selectedRow = dataGridView.Rows[1]; + dataGridView.SetCurrentCell(selectedRow.Cells[0]); + + // Then var selection = control.Selection as IllustrationPointControlItem; - var dataBoundItem = selectedLocationRow.DataBoundItem as IllustrationPointRow; + var dataBoundItem = selectedRow.DataBoundItem as IllustrationPointRow; Assert.NotNull(selection); Assert.NotNull(dataBoundItem); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs =================================================================== diff -u -r69d6acd84acd14d6739e70fad44ef155fe1e0f08 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs (.../LocationsViewSynchronizationTester.cs) (revision 69d6acd84acd14d6739e70fad44ef155fe1e0f08) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs (.../LocationsViewSynchronizationTester.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -35,28 +35,21 @@ /// The type of the locations contained by the view. public abstract class LocationsViewSynchronizationTester where T : class { - /// - /// The test form. - /// - protected Form TestForm; + private Form testForm; + private MockRepository mockRepository; - /// - /// The mock repository. - /// - protected MockRepository MockRepository; - [SetUp] public void Setup() { - TestForm = new Form(); - MockRepository = new MockRepository(); + testForm = new Form(); + mockRepository = new MockRepository(); } [TearDown] public void TearDown() { - TestForm.Dispose(); - MockRepository.VerifyAll(); + testForm.Dispose(); + mockRepository.VerifyAll(); } /// @@ -107,31 +100,19 @@ /// The locations view involved. protected abstract void AddLocationOutputAndNotifyObservers(LocationsView view); - /// - /// Gets the locations data grid view. - /// - /// The locations data grid view. - protected DataGridView GetLocationsDataGridView() + private DataGridView GetLocationsDataGridView() { - return ControlTestHelper.GetDataGridView(TestForm, "DataGridView"); + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); } - /// - /// Gets the locations data grid view control. - /// - /// The locations data grid view control. - protected DataGridViewControl GetLocationsDataGridViewControl() + private DataGridViewControl GetLocationsDataGridViewControl() { - return ControlTestHelper.GetDataGridViewControl(TestForm, "DataGridViewControl"); + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); } - /// - /// Gets the illustration points control. - /// - /// The illustration points control. - protected IllustrationPointsControl GetIllustrationPointsControl() + private IllustrationPointsControl GetIllustrationPointsControl() { - return ControlTestHelper.GetControls(TestForm, "IllustrationPointsControl").Single(); + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); } private DataGridView GetIllustrationPointsDataGridView() @@ -145,8 +126,8 @@ public void GivenFullyConfiguredView_WhenSelectingLocationWithoutOutput_ThenIllustrationPointsControlDataSetToEmptyEnumeration() { // Given - ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -162,8 +143,8 @@ public void GivenFullyConfiguredView_WhenSelectingLocationWithoutGeneralResult_ThenIllustrationPointsControlDataSetToEmptyEnumeration() { // Given - ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -179,8 +160,8 @@ public void GivenFullyConfiguredView_WhenSelectingLocationWithGeneralResult_ThenGeneralResultSetOnIllustrationPointsControlData() { // Given - ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -196,8 +177,8 @@ public void GivenFullyConfiguredViewWithFilledIllustrationPointsControl_WhenOutputCleared_ThenDataGridViewsUpdated() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); DataGridViewRowCollection locationsDataGridViewRows = locationsDataGridView.Rows; @@ -237,8 +218,8 @@ public void GivenFullyConfiguredView_WhenSelectingLocation_ThenSelectionUpdated() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); @@ -255,8 +236,8 @@ public void GivenFullyConfiguredViewWithLocationSelection_WhenDatabaseReplaced_ThenSelectionUpdated() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -279,8 +260,8 @@ public void GivenFullyConfiguredViewWithLocationSelection_WhenOutputCleared_ThenSelectionPreserved() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -303,8 +284,8 @@ public void GivenFullyConfiguredViewWithLocationSelection_WhenOutputUpdated_ThenSelectionPreserved() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -327,8 +308,8 @@ public void GivenFullyConfiguredView_WhenSelectingIllustrationPoint_ThenSelectionUpdated() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -345,8 +326,8 @@ public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenDatabaseReplaced_ThenSelectionSetToLocation() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -370,8 +351,8 @@ public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputCleared_ThenSelectionSetToLocation() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; @@ -395,8 +376,8 @@ public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputUpdated_ThenSelectionPreserved() { // Given - LocationsView view = ShowFullyConfiguredLocationsView(TestForm); - MockRepository.ReplayAll(); + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + mockRepository.ReplayAll(); DataGridView locationsDataGridView = GetLocationsDataGridView(); locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r69d6acd84acd14d6739e70fad44ef155fe1e0f08 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 69d6acd84acd14d6739e70fad44ef155fe1e0f08) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -50,7 +50,7 @@ namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.Views { [TestFixture] - public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest : LocationsViewSynchronizationTester + public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -59,12 +59,29 @@ private const int locationColumnIndex = 4; private const int locationDesignWaterlevelColumnIndex = 5; + private Form testForm; + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + [Test] public void DefaultConstructor_DefaultValues() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call using (var view = new GrassCoverErosionOutwardsDesignWaterLevelLocationsView(assessmentSection)) @@ -79,11 +96,11 @@ public void Constructor_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowDesignWaterLevelLocationsView(assessmentSection, TestForm); + ShowDesignWaterLevelLocationsView(assessmentSection, testForm); // Assert DataGridView locationsDataGridView = GetLocationsDataGridView(); @@ -107,18 +124,18 @@ var locationDesignWaterlevelColumn = (DataGridViewTextBoxColumn) locationsDataGridView.Columns[locationDesignWaterlevelColumnIndex]; Assert.AreEqual("Waterstand bij doorsnede-eis [m+NAP]", locationDesignWaterlevelColumn.HeaderText); - var button = (Button) TestForm.Controls.Find("CalculateForSelectedButton", true).First(); + var button = (Button) testForm.Controls.Find("CalculateForSelectedButton", true).First(); Assert.IsFalse(button.Enabled); } [Test] public void DesignWaterLevelLocationsView_WithNonIObservableList_ThrowsInvalidCastException() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowDesignWaterLevelLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowDesignWaterLevelLocationsView(assessmentSection, testForm); var locations = new List { @@ -136,11 +153,11 @@ public void DesignWaterLevelLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); // Assert DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -197,10 +214,10 @@ public void DesignWaterLevelLocationsView_HydraulicBoundaryDatabaseUpdated_DataGridViewCorrectlyUpdated() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); var locations = (ObservableList) view.Data; // Precondition @@ -246,10 +263,10 @@ public void DesignWaterLevelLocationsView_HydraulicBoundaryDatabaseUpdated_IllustrationPointsControlCorrectlyUpdated() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -284,16 +301,16 @@ public void CalculateForSelectedButton_OneSelected_CallsCalculateDesignWaterLevelsSelectionNotChanged(bool isSuccessful) { // Setup - var assessmentSection = MockRepository.Stub(); + var assessmentSection = mockRepository.Stub(); assessmentSection.Stub(ass => ass.Id).Return(string.Empty); assessmentSection.Stub(ass => ass.FailureMechanismContribution) .Return(new FailureMechanismContribution(Enumerable.Empty(), 1)); assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); - var guiService = MockRepository.StrictMock(); + var guiService = mockRepository.StrictMock(); - var observer = MockRepository.StrictMock(); + var observer = mockRepository.StrictMock(); if (isSuccessful) { @@ -309,11 +326,11 @@ messageProvider = (ICalculationMessageProvider) invocation.Arguments[3]; }).Return(isSuccessful); - MockRepository.ReplayAll(); + mockRepository.ReplayAll(); assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); - GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); var locations = (ObservableList) view.Data; DataGridView locationsDataGridView = GetLocationsDataGridView(); object dataGridViewSource = locationsDataGridView.DataSource; @@ -327,7 +344,7 @@ Contribution = 10 }; view.CalculationGuiService = guiService; - var buttonTester = new ButtonTester("CalculateForSelectedButton", TestForm); + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call buttonTester.Click(); @@ -347,16 +364,16 @@ public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call TestDelegate test = () => button.Click(); @@ -375,10 +392,10 @@ string expectedErrorMessage) { // Given - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(assessmentSection, testForm); // When if (rowSelected) @@ -402,6 +419,21 @@ Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); } + private DataGridView GetLocationsDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); + } + + private DataGridViewControl GetLocationsDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private IllustrationPointsControl GetIllustrationPointsControl() + { + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); + } + private static IEnumerable CreateControlItems( GeneralResult generalResult) { @@ -487,53 +519,53 @@ return view; } - #region LocationsViewSynchronizationTester implementation - - protected override int OutputColumnIndex + [TestFixture] + private class DesignWaterLevelLocationsViewSynchronizationTest : LocationsViewSynchronizationTester { - get + protected override int OutputColumnIndex { - return locationDesignWaterlevelColumnIndex; + get + { + return locationDesignWaterlevelColumnIndex; + } } - } - protected override object GetLocationSelection(LocationsView view, object selectedRowObject) - { - return new GrassCoverErosionOutwardsDesignWaterLevelLocationContext((ObservableList) view.Data, - ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); - } + protected override object GetLocationSelection(LocationsView view, object selectedRowObject) + { + return new GrassCoverErosionOutwardsDesignWaterLevelLocationContext((ObservableList) view.Data, + ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); + } - protected override LocationsView ShowFullyConfiguredLocationsView(Form form) - { - return ShowFullyConfiguredDesignWaterLevelLocationsView(new ObservableTestAssessmentSectionStub(), form); - } + protected override LocationsView ShowFullyConfiguredLocationsView(Form form) + { + return ShowFullyConfiguredDesignWaterLevelLocationsView(new ObservableTestAssessmentSectionStub(), form); + } - protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); + protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); - locations.Clear(); - locations.Add(hydraulicBoundaryLocation); - locations.NotifyObservers(); - } + locations.Clear(); + locations.Add(hydraulicBoundaryLocation); + locations.NotifyObservers(); + } - protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; + protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; - locations.ForEach(loc => loc.DesignWaterLevelCalculation.Output = null); - locations.NotifyObservers(); - } + locations.ForEach(loc => loc.DesignWaterLevelCalculation.Output = null); + locations.NotifyObservers(); + } - protected override void AddLocationOutputAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; + protected override void AddLocationOutputAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; - locations.First().DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); - locations.NotifyObservers(); + locations.First().DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); + locations.NotifyObservers(); + } } - - #endregion } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs =================================================================== diff -u -r69d6acd84acd14d6739e70fad44ef155fe1e0f08 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 69d6acd84acd14d6739e70fad44ef155fe1e0f08) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -50,7 +50,7 @@ namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.Views { [TestFixture] - public class GrassCoverErosionOutwardsWaveHeightLocationsViewTest : LocationsViewSynchronizationTester + public class GrassCoverErosionOutwardsWaveHeightLocationsViewTest { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -59,12 +59,29 @@ private const int locationColumnIndex = 4; private const int locationWaveHeightColumnIndex = 5; + private Form testForm; + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + [Test] public void DefaultConstructor_DefaultValues() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView(assessmentSection)) @@ -79,11 +96,11 @@ public void Constructor_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowWaveHeightLocationsView(assessmentSection, TestForm); + ShowWaveHeightLocationsView(assessmentSection, testForm); // Assert DataGridView locationsDataGridView = GetLocationsDataGridView(); @@ -107,18 +124,18 @@ var locationWaveHeightColumn = (DataGridViewTextBoxColumn) locationsDataGridView.Columns[locationWaveHeightColumnIndex]; Assert.AreEqual("Golfhoogte bij doorsnede-eis [m]", locationWaveHeightColumn.HeaderText); - var button = (Button) TestForm.Controls.Find("CalculateForSelectedButton", true).First(); + var button = (Button) testForm.Controls.Find("CalculateForSelectedButton", true).First(); Assert.IsFalse(button.Enabled); } [Test] public void WaveHeightLocationsView_WithNonIObservableList_ThrowsInvalidCastException() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowWaveHeightLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowWaveHeightLocationsView(assessmentSection, testForm); var locations = new List { @@ -136,11 +153,11 @@ public void WaveHeightLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); // Assert DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -197,10 +214,10 @@ public void WaveHeightLocationsView_HydraulicBoundaryLocationsUpdated_DataGridViewCorrectlyUpdated() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); var locations = (ObservableList) view.Data; // Precondition @@ -246,10 +263,10 @@ public void WaveHeightLocationsView_HydraulicBoundaryLocationsUpdated_IllustrationPointsControlCorrectlyUpdated() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -284,17 +301,17 @@ public void CalculateForSelectedButton_OneSelected_CallsCalculateWaveHeightsSelectionNotChanged(bool isSuccessful) { // Setup - var assessmentSection = MockRepository.Stub(); + var assessmentSection = mockRepository.Stub(); assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); assessmentSection.Stub(ass => ass.Id).Return(string.Empty); assessmentSection.Stub(ass => ass.FailureMechanismContribution) .Return(new FailureMechanismContribution(Enumerable.Empty(), 1)); assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); - var guiService = MockRepository.StrictMock(); + var guiService = mockRepository.StrictMock(); - var observer = MockRepository.StrictMock(); + var observer = mockRepository.StrictMock(); if (isSuccessful) { @@ -310,9 +327,9 @@ messageProvider = (ICalculationMessageProvider) invocation.Arguments[3]; }).Return(isSuccessful); - MockRepository.ReplayAll(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); var locations = (ObservableList) view.Data; DataGridView locationsDataGridView = GetLocationsDataGridView(); object dataGridViewSource = locationsDataGridView.DataSource; @@ -326,7 +343,7 @@ { Contribution = 10 }; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call button.Click(); @@ -346,16 +363,16 @@ public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call TestDelegate test = () => button.Click(); @@ -374,10 +391,10 @@ string expectedErrorMessage) { // Given - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); - GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, TestForm); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(assessmentSection, testForm); // When if (rowSelected) @@ -401,6 +418,21 @@ Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); } + private DataGridView GetLocationsDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); + } + + private DataGridViewControl GetLocationsDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private IllustrationPointsControl GetIllustrationPointsControl() + { + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); + } + private static IEnumerable CreateControlItems( GeneralResult generalResult) { @@ -486,53 +518,53 @@ return view; } - #region LocationsViewSynchronizationTester implementation - - protected override int OutputColumnIndex + [TestFixture] + private class WaveHeightLocationsViewSynchronizationTest : LocationsViewSynchronizationTester { - get + protected override int OutputColumnIndex { - return locationWaveHeightColumnIndex; + get + { + return locationWaveHeightColumnIndex; + } } - } - protected override object GetLocationSelection(LocationsView view, object selectedRowObject) - { - return new GrassCoverErosionOutwardsWaveHeightLocationContext((ObservableList) view.Data, - ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); - } + protected override object GetLocationSelection(LocationsView view, object selectedRowObject) + { + return new GrassCoverErosionOutwardsWaveHeightLocationContext((ObservableList) view.Data, + ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); + } - protected override LocationsView ShowFullyConfiguredLocationsView(Form form) - { - return ShowFullyConfiguredWaveHeightLocationsView(new ObservableTestAssessmentSectionStub(), form); - } + protected override LocationsView ShowFullyConfiguredLocationsView(Form form) + { + return ShowFullyConfiguredWaveHeightLocationsView(new ObservableTestAssessmentSectionStub(), form); + } - protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); + protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); - locations.Clear(); - locations.Add(hydraulicBoundaryLocation); - locations.NotifyObservers(); - } + locations.Clear(); + locations.Add(hydraulicBoundaryLocation); + locations.NotifyObservers(); + } - protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; + protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; - locations.ForEach(loc => loc.WaveHeightCalculation.Output = null); - locations.NotifyObservers(); - } + locations.ForEach(loc => loc.WaveHeightCalculation.Output = null); + locations.NotifyObservers(); + } - protected override void AddLocationOutputAndNotifyObservers(LocationsView view) - { - var locations = (ObservableList) view.Data; + protected override void AddLocationOutputAndNotifyObservers(LocationsView view) + { + var locations = (ObservableList) view.Data; - locations.First().WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); - locations.NotifyObservers(); + locations.First().WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); + locations.NotifyObservers(); + } } - - #endregion } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r69d6acd84acd14d6739e70fad44ef155fe1e0f08 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision 69d6acd84acd14d6739e70fad44ef155fe1e0f08) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -45,7 +45,7 @@ namespace Ringtoets.Integration.Forms.Test.Views { [TestFixture] - public class DesignWaterLevelLocationsViewTest : LocationsViewSynchronizationTester + public class DesignWaterLevelLocationsViewTest { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -54,12 +54,29 @@ private const int locationColumnIndex = 4; private const int locationDesignWaterlevelColumnIndex = 5; + private Form testForm; + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + [Test] public void Constructor_ExpectedValues() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call using (var view = new DesignWaterLevelLocationsView(assessmentSection)) @@ -74,11 +91,11 @@ public void Constructor_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowDesignWaterLevelLocationsView(assessmentSection, TestForm); + ShowDesignWaterLevelLocationsView(assessmentSection, testForm); // Assert DataGridView locationsDataGridView = GetLocationsDataGridView(); @@ -102,15 +119,15 @@ var locationDesignWaterlevelColumn = (DataGridViewTextBoxColumn) locationsDataGridView.Columns[locationDesignWaterlevelColumnIndex]; Assert.AreEqual("Toetspeil [m+NAP]", locationDesignWaterlevelColumn.HeaderText); - var button = (Button) TestForm.Controls.Find("CalculateForSelectedButton", true).First(); + var button = (Button) testForm.Controls.Find("CalculateForSelectedButton", true).First(); Assert.IsFalse(button.Enabled); } [Test] public void DesignWaterLevelLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup & Call - ShowFullyConfiguredDesignWaterLevelLocationsView(TestForm); + ShowFullyConfiguredDesignWaterLevelLocationsView(testForm); // Assert DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -167,7 +184,7 @@ public void DesignWaterLevelLocationsView_HydraulicBoundaryDatabaseUpdated_DataGridViewCorrectlyUpdated() { // Setup - DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(TestForm); + DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(testForm); IAssessmentSection assessmentSection = view.AssessmentSection; var newHydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0) @@ -209,7 +226,7 @@ public void DesignWaterLevelLocationsView_HydraulicBoundaryDatabaseUpdated_IllustrationPointsControlCorrectlyUpdated() { // Setup - DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(TestForm); + DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(testForm); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -242,15 +259,15 @@ public void CalculateForSelectedButton_OneSelected_CallsCalculateDesignWaterLevels(bool isSuccessful) { // Setup - DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(TestForm); + DesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(testForm); IAssessmentSection assessmentSection = view.AssessmentSection; DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var guiService = MockRepository.StrictMock(); + var guiService = mockRepository.StrictMock(); - var observer = MockRepository.StrictMock(); + var observer = mockRepository.StrictMock(); assessmentSection.HydraulicBoundaryDatabase.Attach(observer); if (isSuccessful) @@ -266,10 +283,10 @@ locations = (IEnumerable) invocation.Arguments[1]; messageProvider = (ICalculationMessageProvider) invocation.Arguments[3]; }).Return(isSuccessful); - MockRepository.ReplayAll(); + mockRepository.ReplayAll(); view.CalculationGuiService = guiService; - var buttonTester = new ButtonTester("CalculateForSelectedButton", TestForm); + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call buttonTester.Click(); @@ -286,13 +303,13 @@ public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup - ShowFullyConfiguredDesignWaterLevelLocationsView(TestForm); + ShowFullyConfiguredDesignWaterLevelLocationsView(testForm); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call TestDelegate test = () => button.Click(); @@ -301,6 +318,21 @@ Assert.DoesNotThrow(test); } + private DataGridView GetLocationsDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); + } + + private DataGridViewControl GetLocationsDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private IllustrationPointsControl GetIllustrationPointsControl() + { + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); + } + private static IEnumerable CreateControlItems( GeneralResult generalResult) { @@ -396,61 +428,61 @@ } } - #region LocationsViewSynchronizationTester implementation - - protected override int OutputColumnIndex + [TestFixture] + private class DesignWaterLevelLocationsViewSynchronizationTest : LocationsViewSynchronizationTester { - get + protected override int OutputColumnIndex { - return locationDesignWaterlevelColumnIndex; + get + { + return locationDesignWaterlevelColumnIndex; + } } - } - protected override object GetLocationSelection(LocationsView view, object selectedRowObject) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override object GetLocationSelection(LocationsView view, object selectedRowObject) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - return new DesignWaterLevelLocationContext(assessmentSection.HydraulicBoundaryDatabase, - ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); - } + return new DesignWaterLevelLocationContext(assessmentSection.HydraulicBoundaryDatabase, + ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); + } - protected override LocationsView ShowFullyConfiguredLocationsView(Form form) - { - return ShowFullyConfiguredDesignWaterLevelLocationsView(form); - } + protected override LocationsView ShowFullyConfiguredLocationsView(Form form) + { + return ShowFullyConfiguredDesignWaterLevelLocationsView(form); + } - protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); - - assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) { - Locations = + IAssessmentSection assessmentSection = view.AssessmentSection; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); + + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - hydraulicBoundaryLocation - } - }; + Locations = + { + hydraulicBoundaryLocation + } + }; - assessmentSection.NotifyObservers(); - } + assessmentSection.NotifyObservers(); + } - protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - assessmentSection.HydraulicBoundaryDatabase.Locations.ForEach(loc => loc.DesignWaterLevelCalculation.Output = null); - assessmentSection.NotifyObservers(); - } + assessmentSection.HydraulicBoundaryDatabase.Locations.ForEach(loc => loc.DesignWaterLevelCalculation.Output = null); + assessmentSection.NotifyObservers(); + } - protected override void AddLocationOutputAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override void AddLocationOutputAndNotifyObservers(LocationsView view) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - assessmentSection.HydraulicBoundaryDatabase.Locations.First().DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); - assessmentSection.NotifyObservers(); + assessmentSection.HydraulicBoundaryDatabase.Locations.First().DesignWaterLevelCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); + assessmentSection.NotifyObservers(); + } } - - #endregion } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs =================================================================== diff -u -r69d6acd84acd14d6739e70fad44ef155fe1e0f08 -rf0267c59b04d7626cc634fd0a1c14d9b02c061ea --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision 69d6acd84acd14d6739e70fad44ef155fe1e0f08) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision f0267c59b04d7626cc634fd0a1c14d9b02c061ea) @@ -43,7 +43,7 @@ namespace Ringtoets.Integration.Forms.Test.Views { [TestFixture] - public class WaveHeightLocationsViewTest : LocationsViewSynchronizationTester + public class WaveHeightLocationsViewTest { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -52,12 +52,29 @@ private const int locationColumnIndex = 4; private const int locationWaveHeightColumnIndex = 5; + private Form testForm; + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + [Test] public void Constructor_ExpectedValues() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call using (var view = new WaveHeightLocationsView(assessmentSection)) @@ -72,11 +89,11 @@ public void Constructor_DataGridViewCorrectlyInitialized() { // Setup - var assessmentSection = MockRepository.Stub(); - MockRepository.ReplayAll(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); // Call - ShowWaveHeightLocationsView(assessmentSection, TestForm); + ShowWaveHeightLocationsView(assessmentSection, testForm); // Assert DataGridView locationsDataGridView = GetLocationsDataGridView(); @@ -100,15 +117,15 @@ var locationWaveHeightColumn = (DataGridViewTextBoxColumn) locationsDataGridView.Columns[locationWaveHeightColumnIndex]; Assert.AreEqual("Hs [m]", locationWaveHeightColumn.HeaderText); - var button = (Button) TestForm.Controls.Find("CalculateForSelectedButton", true).First(); + var button = (Button) testForm.Controls.Find("CalculateForSelectedButton", true).First(); Assert.IsFalse(button.Enabled); } [Test] public void WaveHeightLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup & Call - ShowFullyConfiguredWaveHeightLocationsView(TestForm); + ShowFullyConfiguredWaveHeightLocationsView(testForm); // Assert DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -165,7 +182,7 @@ public void WaveHeightLocationsView_HydraulicBoundaryDatabaseUpdated_DataGridViewCorrectlyUpdated() { // Setup - WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(TestForm); + WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(testForm); IAssessmentSection assessmentSection = view.AssessmentSection; var newHydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0) @@ -206,7 +223,7 @@ public void WaveHeightLocationsView_HydraulicBoundaryDatabaseUpdated_IllustrationPointsControlCorrectlyUpdated() { // Setup - WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(TestForm); + WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(testForm); IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); @@ -240,15 +257,15 @@ public void CalculateForSelectedButton_OneSelected_CallsCalculateWaveHeights(bool isSuccessful) { // Setup - WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(TestForm); + WaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(testForm); IAssessmentSection assessmentSection = view.AssessmentSection; DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var guiService = MockRepository.StrictMock(); + var guiService = mockRepository.StrictMock(); - var observer = MockRepository.StrictMock(); + var observer = mockRepository.StrictMock(); assessmentSection.HydraulicBoundaryDatabase.Attach(observer); if (isSuccessful) @@ -259,10 +276,10 @@ IEnumerable locations = null; guiService.Expect(ch => ch.CalculateWaveHeights(null, null, 1, null)).IgnoreArguments().WhenCalled( invocation => { locations = (IEnumerable) invocation.Arguments[1]; }).Return(isSuccessful); - MockRepository.ReplayAll(); + mockRepository.ReplayAll(); view.CalculationGuiService = guiService; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call button.Click(); @@ -278,13 +295,13 @@ public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup - ShowFullyConfiguredWaveHeightLocationsView(TestForm); + ShowFullyConfiguredWaveHeightLocationsView(testForm); DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); DataGridViewRowCollection rows = locationsDataGridViewControl.Rows; rows[0].Cells[locationCalculateColumnIndex].Value = true; - var button = new ButtonTester("CalculateForSelectedButton", TestForm); + var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call TestDelegate test = () => button.Click(); @@ -293,6 +310,21 @@ Assert.DoesNotThrow(test); } + private DataGridView GetLocationsDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); + } + + private DataGridViewControl GetLocationsDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private IllustrationPointsControl GetIllustrationPointsControl() + { + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); + } + private static IEnumerable CreateControlItems( GeneralResult generalResult) { @@ -388,61 +420,61 @@ } } - #region LocationsViewSynchronizationTester implementation - - protected override int OutputColumnIndex + [TestFixture] + public class WaveHeightLocationsViewSynchronizationTest : LocationsViewSynchronizationTester { - get + protected override int OutputColumnIndex { - return locationWaveHeightColumnIndex; + get + { + return locationWaveHeightColumnIndex; + } } - } - protected override object GetLocationSelection(LocationsView view, object selectedRowObject) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override object GetLocationSelection(LocationsView view, object selectedRowObject) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - return new WaveHeightLocationContext(assessmentSection.HydraulicBoundaryDatabase, - ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); - } + return new WaveHeightLocationContext(assessmentSection.HydraulicBoundaryDatabase, + ((HydraulicBoundaryLocationRow) selectedRowObject).CalculatableObject); + } - protected override LocationsView ShowFullyConfiguredLocationsView(Form form) - { - return ShowFullyConfiguredWaveHeightLocationsView(form); - } + protected override LocationsView ShowFullyConfiguredLocationsView(Form form) + { + return ShowFullyConfiguredWaveHeightLocationsView(form); + } - protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); - - assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + protected override void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view) { - Locations = + IAssessmentSection assessmentSection = view.AssessmentSection; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0); + + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - hydraulicBoundaryLocation - } - }; + Locations = + { + hydraulicBoundaryLocation + } + }; - assessmentSection.NotifyObservers(); - } + assessmentSection.NotifyObservers(); + } - protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override void ClearLocationOutputAndNotifyObservers(LocationsView view) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - assessmentSection.HydraulicBoundaryDatabase.Locations.ForEach(loc => loc.WaveHeightCalculation.Output = null); - assessmentSection.NotifyObservers(); - } + assessmentSection.HydraulicBoundaryDatabase.Locations.ForEach(loc => loc.WaveHeightCalculation.Output = null); + assessmentSection.NotifyObservers(); + } - protected override void AddLocationOutputAndNotifyObservers(LocationsView view) - { - IAssessmentSection assessmentSection = view.AssessmentSection; + protected override void AddLocationOutputAndNotifyObservers(LocationsView view) + { + IAssessmentSection assessmentSection = view.AssessmentSection; - assessmentSection.HydraulicBoundaryDatabase.Locations.First().WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); - assessmentSection.NotifyObservers(); + assessmentSection.HydraulicBoundaryDatabase.Locations.First().WaveHeightCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); + assessmentSection.NotifyObservers(); + } } - - #endregion } } \ No newline at end of file