Fisheye: Tag 4c8ed944e7dc94678840b6f7b1ff87f6110871f2 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewDataSynchronizationTester.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -0,0 +1,397 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.DataGrid; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms.TestUtil +{ + /// + /// Class for testing data and selection synchronization in derivatives. + /// + /// The type of the locations contained by the view. + public abstract class LocationsViewSynchronizationTester where T : class + { + protected Form testForm; + protected MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + + /// + /// Gets the index of the column containing the locations output. + /// + protected abstract int OutputColumnIndex { get; } + + /// + /// Method for obtaining the view selection object related to the selected location row. + /// + /// The locations view involved. + /// The selected location row object. + /// The view selection object. + protected abstract object GetLocationSelection(LocationsView view, object selectedRowObject); + + /// + /// Method for showing a fully configured locations view. + /// + /// The form to use for showing the view. + /// + /// The view should contain the following location row data: + /// + /// Row 1: location without output + /// Row 2: location with design water level output (but without general result) + /// Row 3: location with wave height output (but without general result) + /// Row 4: location with flag for parsing the general result set to true + /// Row 5: location with output containing a general result with two top level illustration points + /// + /// + /// The fully configured locations view. + protected abstract LocationsView ShowFullyConfiguredLocationsView(Form form); + + /// + /// Method for replacing the hydraulic boundary database as well as notifying the observers. + /// + /// The locations view involved. + protected abstract void ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(LocationsView view); + + /// + /// Method for clearing all location output as well as notifying the observers. + /// + /// The locations view involved. + protected abstract void ClearLocationOutputAndNotifyObservers(LocationsView view); + + /// + /// Method for adding some location output as well as notifying the observers. + /// + /// The locations view involved. + protected abstract void AddLocationOutputAndNotifyObservers(LocationsView view); + + 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 DataGridView GetIllustrationPointsDataGridView() + { + return ControlTestHelper.GetDataGridView(GetIllustrationPointsControl(), "DataGridView"); + } + + #region Data synchronization + + [Test] + public void GivenFullyConfiguredView_WhenSelectingLocationWithoutOutput_ThenIllustrationPointsControlDataSetToEmptyEnumeration() + { + // Given + ShowFullyConfiguredLocationsView(testForm); + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); + + // When + locationsDataGridViewControl.SetCurrentCell(locationsDataGridViewControl.GetCell(0, 1)); + + // Then + CollectionAssert.IsEmpty(illustrationPointsControl.Data); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingLocationWithoutGeneralResult_ThenIllustrationPointsControlDataSetToEmptyEnumeration() + { + // Given + ShowFullyConfiguredLocationsView(testForm); + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); + + // When + locationsDataGridViewControl.SetCurrentCell(locationsDataGridViewControl.GetCell(1, 0)); + + // Then + CollectionAssert.IsEmpty(illustrationPointsControl.Data); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingLocationWithGeneralResult_ThenGeneralResultSetOnIllustrationPointsControlData() + { + // Given + ShowFullyConfiguredLocationsView(testForm); + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl locationsDataGridViewControl = GetLocationsDataGridViewControl(); + + // When + locationsDataGridViewControl.SetCurrentCell(locationsDataGridViewControl.GetCell(4, 0)); + + // Then + Assert.AreEqual(2, illustrationPointsControl.Data.Count()); + } + + [Test] + public void GivenFullyConfiguredViewWithFilledIllustrationPointsControl_WhenOutputCleared_ThenDataGridViewsUpdated() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + DataGridView locationsDataGridView = GetLocationsDataGridView(); + DataGridViewRowCollection locationsDataGridViewRows = locationsDataGridView.Rows; + locationsDataGridView.CurrentCell = locationsDataGridViewRows[4].Cells[0]; + + // Precondition + Assert.AreEqual(5, locationsDataGridViewRows.Count); + Assert.AreEqual("-", locationsDataGridViewRows[0].Cells[OutputColumnIndex].FormattedValue); + Assert.AreNotEqual("-", locationsDataGridViewRows[1].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[2].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[3].Cells[OutputColumnIndex].FormattedValue); + Assert.AreNotEqual("-", locationsDataGridViewRows[4].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual(2, GetIllustrationPointsControl().Data.Count()); + + var refreshed = false; + locationsDataGridView.Invalidated += (sender, args) => refreshed = true; + + // When + ClearLocationOutputAndNotifyObservers(view); + + // Then + Assert.IsTrue(refreshed); + Assert.AreEqual(5, locationsDataGridViewRows.Count); + Assert.AreEqual("-", locationsDataGridViewRows[0].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[1].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[2].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[3].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", locationsDataGridViewRows[4].Cells[OutputColumnIndex].FormattedValue); + CollectionAssert.IsEmpty(GetIllustrationPointsControl().Data); + } + + #endregion + + #region Selection synchronization + + [Test] + public void GivenFullyConfiguredView_WhenSelectingLocation_ThenSelectionUpdated() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + + // When + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + + // Then + DataGridViewRow currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithLocationSelection_WhenDatabaseReplaced_ThenSelectionUpdated() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + + // Precondition + DataGridViewRow currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + + // When + ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(view); + + // Then + currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(0, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithLocationSelection_WhenOutputCleared_ThenSelectionPreserved() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + + // Precondition + DataGridViewRow currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + + // When + ClearLocationOutputAndNotifyObservers(view); + + // Then + currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithLocationSelection_WhenOutputUpdated_ThenSelectionPreserved() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + + // Precondition + DataGridViewRow currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + + // When + AddLocationOutputAndNotifyObservers(view); + + // Then + currentLocationRow = GetLocationsDataGridViewControl().CurrentRow; + Assert.AreEqual(4, currentLocationRow.Index); + Assert.AreEqual(GetLocationSelection(view, currentLocationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingIllustrationPoint_ThenSelectionUpdated() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + + // When + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Then + var selection = view.Selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(selection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, selection.TopLevelSubMechanismIllustrationPoint); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenDatabaseReplaced_ThenSelectionSetToLocation() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(4, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + var selection = view.Selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(selection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, selection.TopLevelSubMechanismIllustrationPoint); + + // When + ReplaceHydraulicBoundaryDatabaseAndNotifyObservers(view); + + // Then + Assert.AreEqual(0, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(GetLocationSelection(view, locationsDataGridView.CurrentRow?.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputCleared_ThenSelectionSetToLocation() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(4, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + var selection = view.Selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(selection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, selection.TopLevelSubMechanismIllustrationPoint); + + // When + ClearLocationOutputAndNotifyObservers(view); + + // Then + Assert.AreEqual(4, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(GetLocationSelection(view, locationsDataGridView.CurrentRow?.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputUpdated_ThenSelectionPreserved() + { + // Given + LocationsView view = ShowFullyConfiguredLocationsView(testForm); + + DataGridView locationsDataGridView = GetLocationsDataGridView(); + locationsDataGridView.CurrentCell = locationsDataGridView.Rows[4].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(4, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + var selection = view.Selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(selection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, selection.TopLevelSubMechanismIllustrationPoint); + + // When + AddLocationOutputAndNotifyObservers(view); + + // Then + Assert.AreEqual(4, locationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + selection = view.Selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(selection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, selection.TopLevelSubMechanismIllustrationPoint); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj =================================================================== diff -u -r2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b -r4c8ed944e7dc94678840b6f7b1ff87f6110871f2 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision 2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -54,7 +54,7 @@ Properties\GlobalAssembly.cs - + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b -r4c8ed944e7dc94678840b6f7b1ff87f6110871f2 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -50,7 +50,7 @@ namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.Views { [TestFixture] - public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest : LocationsViewDataSynchronizationTester + public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest : LocationsViewSynchronizationTester { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -502,7 +502,7 @@ return view; } - #region LocationsViewDataSynchronizationTester implementation + #region LocationsViewSynchronizationTester implementation protected override int OutputColumnIndex { Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs =================================================================== diff -u -r2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b -r4c8ed944e7dc94678840b6f7b1ff87f6110871f2 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -50,7 +50,7 @@ namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.Views { [TestFixture] - public class GrassCoverErosionOutwardsWaveHeightLocationsViewTest : LocationsViewDataSynchronizationTester + public class GrassCoverErosionOutwardsWaveHeightLocationsViewTest : LocationsViewSynchronizationTester { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -501,7 +501,7 @@ return view; } - #region LocationsViewDataSynchronizationTester implementation + #region LocationsViewSynchronizationTester implementation protected override int OutputColumnIndex { Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b -r4c8ed944e7dc94678840b6f7b1ff87f6110871f2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision 2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelLocationsViewTest.cs (.../DesignWaterLevelLocationsViewTest.cs) (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -45,7 +45,7 @@ namespace Ringtoets.Integration.Forms.Test.Views { [TestFixture] - public class DesignWaterLevelLocationsViewTest : LocationsViewDataSynchronizationTester + public class DesignWaterLevelLocationsViewTest : LocationsViewSynchronizationTester { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -403,7 +403,7 @@ } } - #region LocationsViewDataSynchronizationTester implementation + #region LocationsViewSynchronizationTester implementation protected override int OutputColumnIndex { Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs =================================================================== diff -u -r2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b -r4c8ed944e7dc94678840b6f7b1ff87f6110871f2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision 2fac008f9a91a37ac4300ec2e0cdf2b4e5eeea1b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightLocationsViewTest.cs (.../WaveHeightLocationsViewTest.cs) (revision 4c8ed944e7dc94678840b6f7b1ff87f6110871f2) @@ -43,7 +43,7 @@ namespace Ringtoets.Integration.Forms.Test.Views { [TestFixture] - public class WaveHeightLocationsViewTest : LocationsViewDataSynchronizationTester + public class WaveHeightLocationsViewTest : LocationsViewSynchronizationTester { private const int locationCalculateColumnIndex = 0; private const int includeIllustrationPointsColumnIndex = 1; @@ -395,7 +395,7 @@ } } - #region LocationsViewDataSynchronizationTester implementation + #region LocationsViewSynchronizationTester implementation protected override int OutputColumnIndex {