Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj =================================================================== diff -u -r9a196c8bc554a2e97ff094d7ffb2e99c42eb04fd -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision 9a196c8bc554a2e97ff094d7ffb2e99c42eb04fd) +++ Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -44,7 +44,7 @@ Properties\GlobalAssembly.cs - + Code @@ -56,6 +56,10 @@ + + {9A2D67E6-26AC-4D17-B11A-2B4372F2F572} + Core.Common.Controls + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} Core.Common.Gui Fisheye: Tag be9ffe357aaf542c7bcec7f32929028081223566 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Gui.TestUtil.Test/GuiTestHelperTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/PluginTestHelperTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.TestUtil.Test/PluginTestHelperTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.TestUtil.Test/PluginTestHelperTest.cs (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -0,0 +1,191 @@ +// Copyright (C) Stichting Deltares 2016. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Common.Controls.Views; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; + +namespace Core.Common.Gui.TestUtil.Test +{ + [TestFixture] + public class PluginTestHelperTest + { + [Test] + public void AssertPropertyInfoDefined_NullInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertPropertyInfoDefined(null, typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertPropertyInfoDefined_NoInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertPropertyInfoDefined(new PropertyInfo[0], typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertPropertyInfoDefined_NoMatchingInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertPropertyInfoDefined(new PropertyInfo[] + { + new PropertyInfo() + }, typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertPropertyInfoDefined_MultipleInfosSingleMatching_ReturnsMatchingInfoFromList() + { + // Call + var foundInfo = PluginTestHelper.AssertPropertyInfoDefined(new [] + { + new PropertyInfo(), + new PropertyInfo() + }, typeof(int), typeof(IObjectProperties)); + + // Assert + Assert.AreEqual(typeof(int), foundInfo.DataType); + Assert.AreEqual(typeof(IObjectProperties), foundInfo.PropertyObjectType); + } + + [Test] + public void AssertViewInfoDefined_WithoutViewDataTypeNullInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(null, typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithoutViewDataTypeNoInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(new ViewInfo[0], typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithoutViewDataTypeNoMatchingInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(new ViewInfo[] + { + new ViewInfo() + }, typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithoutViewDataTypeMultipleInfosSingleMatching_ReturnsMatchingInfoFromList() + { + // Call + var foundInfo = PluginTestHelper.AssertViewInfoDefined(new[] + { + new ViewInfo(), + new ViewInfo() + }, typeof(int), typeof(IView)); + + // Assert + Assert.AreEqual(typeof(int), foundInfo.DataType); + Assert.AreEqual(typeof(IView), foundInfo.ViewType); + } + + [Test] + public void AssertViewInfoDefined_WithViewDataTypeNullInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(null, typeof(object), typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithViewDataTypeNoInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(new ViewInfo[0], typeof(object), typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithViewDataTypeNoMatchingInfos_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(new ViewInfo[] + { + new ViewInfo() + }, typeof(object), typeof(object), typeof(object)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithViewDataTypeMultipleInfosDifferentViewDataType_ThrowsAssertionException() + { + // Call + TestDelegate test = () => PluginTestHelper.AssertViewInfoDefined(new[] + { + new ViewInfo(), + new ViewInfo() + }, typeof(int), typeof(object), typeof(IView)); + + // Assert + Assert.Throws(test); + } + + [Test] + public void AssertViewInfoDefined_WithViewDataTypeMultipleInfosSingleMatching_ReturnsMatchingInfoFromList() + { + // Call + var foundInfo = PluginTestHelper.AssertViewInfoDefined(new[] + { + new ViewInfo(), + new ViewInfo() + }, typeof(int), typeof(string), typeof(IView)); + + // Assert + Assert.AreEqual(typeof(int), foundInfo.DataType); + Assert.AreEqual(typeof(string), foundInfo.ViewDataType); + Assert.AreEqual(typeof(IView), foundInfo.ViewType); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.TestUtil/PluginTestHelper.cs =================================================================== diff -u -r51d8e744ffb2168ca56ca4b6260ad9c2590c0170 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Core/Common/test/Core.Common.Gui.TestUtil/PluginTestHelper.cs (.../PluginTestHelper.cs) (revision 51d8e744ffb2168ca56ca4b6260ad9c2590c0170) +++ Core/Common/test/Core.Common.Gui.TestUtil/PluginTestHelper.cs (.../PluginTestHelper.cs) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -23,7 +23,6 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Gui.Plugin; -using Core.Common.TestUtil; using NUnit.Framework; namespace Core.Common.Gui.TestUtil @@ -63,10 +62,16 @@ /// The type of the data which is set on the view. /// The type of the view. /// The that was found within the collection of . - /// No can be found for type or the found - /// does not define the expected or . - public static ViewInfo AssertContainsViewInfo(IEnumerable viewInfos, Type dataType, Type viewDataType, Type viewType) + /// Thrown when either: + /// + /// is null + /// no can be found for type + /// the found does not define the expected or + /// + /// + public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewDataType, Type viewType) { + Assert.NotNull(viewInfos); var viewInfo = viewInfos.SingleOrDefault(vi => vi.DataType == dataType); Assert.NotNull(viewInfo, "Could not find viewInfo for the dataType {0}", dataType); Assert.AreEqual(viewDataType, viewInfo.ViewDataType); @@ -81,11 +86,15 @@ /// The type of the data which is passed to the and is set on the view. /// The type of the view. /// The that was found within the collection of . - /// No can be found for type or the found - /// does not define the expected . - public static ViewInfo AssertContainsViewInfo(IEnumerable viewInfos, Type dataType, Type viewType) + /// Thrown when either: + /// + /// is null + /// no can be found for type + /// the found does not define the expected + /// + public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewType) { - return AssertContainsViewInfo(viewInfos, dataType, dataType, viewType); + return AssertViewInfoDefined(viewInfos, dataType, dataType, viewType); } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs =================================================================== diff -u -r51d8e744ffb2168ca56ca4b6260ad9c2590c0170 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision 51d8e744ffb2168ca56ca4b6260ad9c2590c0170) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -37,7 +37,7 @@ public GrassCoverErosionOutwardsDesignWaterLevelLocationsView() { - hydraulicBoundaryLocationsObserver = new Observer(() => dataGridViewControl.RefreshDataGridView()); + hydraulicBoundaryLocationsObserver = new Observer(UpdateDataGridViewDataSource); } public override object Data Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Ringtoets.GrassCoverErosionOutwards.Forms.Test.csproj =================================================================== diff -u -r172f313c5afd8dafa9756d9d1600c78ea2e9fcf9 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Ringtoets.GrassCoverErosionOutwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Forms.Test.csproj) (revision 172f313c5afd8dafa9756d9d1600c78ea2e9fcf9) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Ringtoets.GrassCoverErosionOutwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Forms.Test.csproj) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -98,6 +98,7 @@ + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -0,0 +1,314 @@ +// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.Common.Forms.Views; +using Ringtoets.Common.Service.MessageProviders; +using Ringtoets.GrassCoverErosionOutwards.Forms.Views; +using Ringtoets.GrassCoverErosionOutwards.Service.MessageProviders; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test.Views +{ + [TestFixture] + public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest + { + private const int locationCalculateColumnIndex = 0; + private const int locationNameColumnIndex = 1; + private const int locationIdColumnIndex = 2; + private const int locationColumnIndex = 3; + private const int locationDesignWaterlevelColumnIndex = 4; + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + public void DefaultConstructor_DefaultValues() + { + // Call + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelLocationsView()) + { + // Assert + Assert.IsInstanceOf>(view); + Assert.IsNull(view.Data); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Setup & Call + ShowDesignWaterLevelLocationsView(); + + // Assert + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + Assert.AreEqual(5, dataGridView.ColumnCount); + + var locationCalculateColumn = (DataGridViewCheckBoxColumn)dataGridView.Columns[locationCalculateColumnIndex]; + const string expectedLocationCalculateHeaderText = "Berekenen"; + Assert.AreEqual(expectedLocationCalculateHeaderText, locationCalculateColumn.HeaderText); + + var locationNameColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationNameColumnIndex]; + const string expectedLocationNameHeaderText = "Naam"; + Assert.AreEqual(expectedLocationNameHeaderText, locationNameColumn.HeaderText); + + var locationIdColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationIdColumnIndex]; + const string expectedLocationIdHeaderText = "ID"; + Assert.AreEqual(expectedLocationIdHeaderText, locationIdColumn.HeaderText); + + var locationColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationColumnIndex]; + const string expectedLocationHeaderText = "Coördinaten [m]"; + Assert.AreEqual(expectedLocationHeaderText, locationColumn.HeaderText); + + var locationDesignWaterlevelColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationDesignWaterlevelColumnIndex]; + const string expectedLocationDesignWaterHeaderText = "Waterstand bij doorsnede-eis [m+NAP]"; + Assert.AreEqual(expectedLocationDesignWaterHeaderText, locationDesignWaterlevelColumn.HeaderText); + + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); + var button = (Button)buttonTester.TheObject; + Assert.IsFalse(button.Enabled); + } + + [Test] + public void DesignWaterLevelLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() + { + // Setup & Call + ShowFullyConfiguredDesignWaterLevelLocationsView(); + + // Assert + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(3, rows.Count); + + var cells = rows[0].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("1", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("1", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(1, 1).ToString(), cells[locationColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[locationDesignWaterlevelColumnIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("2", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("2", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(2, 2).ToString(), cells[locationColumnIndex].FormattedValue); + Assert.AreEqual(1.23.ToString(CultureInfo.CurrentCulture), cells[locationDesignWaterlevelColumnIndex].FormattedValue); + + cells = rows[2].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("3", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("3", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(3, 3).ToString(), cells[locationColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[locationDesignWaterlevelColumnIndex].FormattedValue); + } + + [Test] + public void DesignWaterLevelLocationsView_HydraulicBoundaryDatabaseUpdated_DataGridViewCorrectlyUpdated() + { + // Setup + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(); + ObservableList locations = (ObservableList) view.Data; + + // Precondition + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(3, rows.Count); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0) + { + DesignWaterLevel = (RoundedDouble) 10.23 + }; + + locations.Clear(); + locations.Add(hydraulicBoundaryLocation); + + // Call + locations.NotifyObservers(); + + // Assert + Assert.AreEqual(1, rows.Count); + var cells = rows[0].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(10, 10).ToString(), cells[locationColumnIndex].FormattedValue); + Assert.AreEqual(hydraulicBoundaryLocation.DesignWaterLevel, cells[locationDesignWaterlevelColumnIndex].Value); + } + + [Test] + public void DesignWaterLevelLocationsView_AssessmentSectionUpdated_DataGridViewCorrectlyUpdated() + { + // Setup + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(); + ObservableList locations = (ObservableList)view.Data; + + // Precondition + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(3, rows.Count); + Assert.AreEqual("-", rows[0].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + Assert.AreEqual(1.23.ToString(CultureInfo.CurrentCulture), rows[1].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + Assert.AreEqual("-", rows[2].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + + locations.ForEach(loc => loc.DesignWaterLevel = (RoundedDouble)double.NaN); + + // Call + locations.NotifyObservers(); + + // Assert + Assert.AreEqual(3, rows.Count); + Assert.AreEqual("-", rows[0].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + Assert.AreEqual("-", rows[1].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + Assert.AreEqual("-", rows[2].Cells[locationDesignWaterlevelColumnIndex].FormattedValue); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void CalculateForSelectedButton_OneSelected_CallsCalculateDesignWaterLevels(bool isSuccessful) + { + // Setup + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(); + ObservableList locations = (ObservableList)view.Data; + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; + + var mockRepository = new MockRepository(); + var guiServiceMock = mockRepository.StrictMock(); + + var observer = mockRepository.StrictMock(); + locations.Attach(observer); + + if (isSuccessful) + { + observer.Expect(o => o.UpdateObserver()); + } + + ICalculationMessageProvider messageProvider = null; + HydraulicBoundaryLocation[] calculatedLocations = null; + guiServiceMock.Expect(ch => ch.CalculateDesignWaterLevels(null, null, null, 1, null)).IgnoreArguments().WhenCalled( + invocation => + { + calculatedLocations = ((IEnumerable)invocation.Arguments[1]).ToArray(); + messageProvider = (ICalculationMessageProvider)invocation.Arguments[4]; + }).Return(isSuccessful); + + IAssessmentSection assessmentSectionStub = mockRepository.Stub(); + assessmentSectionStub.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + assessmentSectionStub.Stub(ass => ass.Id).Return(string.Empty); + assessmentSectionStub.Stub(ass => ass.FailureMechanismContribution) + .Return(new FailureMechanismContribution(Enumerable.Empty(), 1, 1)); + + mockRepository.ReplayAll(); + + view.AssessmentSection = assessmentSectionStub; + + view.CalculationGuiService = guiServiceMock; + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); + + // Call + buttonTester.Click(); + + // Assert + Assert.IsInstanceOf(messageProvider); + Assert.AreEqual(1, calculatedLocations.Length); + HydraulicBoundaryLocation expectedLocation = locations.First(); + Assert.AreEqual(expectedLocation, calculatedLocations.First()); + + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() + { + // Setup + ShowFullyConfiguredDesignWaterLevelLocationsView(); + + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; + + var button = new ButtonTester("CalculateForSelectedButton", testForm); + + // Call + TestDelegate test = () => button.Click(); + + // Assert + Assert.DoesNotThrow(test); + } + + private GrassCoverErosionOutwardsDesignWaterLevelLocationsView ShowDesignWaterLevelLocationsView() + { + var view = new GrassCoverErosionOutwardsDesignWaterLevelLocationsView(); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + + private GrassCoverErosionOutwardsDesignWaterLevelLocationsView ShowFullyConfiguredDesignWaterLevelLocationsView() + { + var view = ShowDesignWaterLevelLocationsView(); + view.Data = new ObservableList + { + new HydraulicBoundaryLocation(1, "1", 1.0, 1.0), + new HydraulicBoundaryLocation(2, "2", 2.0, 2.0) + { + DesignWaterLevel = (RoundedDouble)1.23 + }, + new HydraulicBoundaryLocation(3, "3", 3.0, 3.0) + { + WaveHeight = (RoundedDouble)2.45 + } + }; + return view; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs =================================================================== diff -u -r51d8e744ffb2168ca56ca4b6260ad9c2590c0170 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs (.../GrassCoverErosionOutwardsPluginTest.cs) (revision 51d8e744ffb2168ca56ca4b6260ad9c2590c0170) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs (.../GrassCoverErosionOutwardsPluginTest.cs) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -63,13 +63,13 @@ // Assert Assert.AreEqual(2, viewInfos.Length); - PluginTestHelper.AssertContainsViewInfo( + PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(FailureMechanismSectionResultContext), typeof(IEnumerable), typeof(GrassCoverErosionOutwardsFailureMechanismResultView)); - PluginTestHelper.AssertContainsViewInfo( + PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(GrassCoverErosionOutwardsDesignWaterLevelLocationsContext), typeof(IEnumerable), Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs =================================================================== diff -u -r51d8e744ffb2168ca56ca4b6260ad9c2590c0170 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs) (revision 51d8e744ffb2168ca56ca4b6260ad9c2590c0170) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -21,72 +21,194 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.GuiServices; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; +using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; using Ringtoets.GrassCoverErosionOutwards.Forms.Views; using Ringtoets.HydraRing.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.GrassCoverErosionOutwards.Plugin.Test.ViewInfos { [TestFixture] public class GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest : ViewInfoTest { - protected override Type DataType + [Test] + public void AfterCreate_Always_SetsExpectedProperties() { - get + var mockRepository = new MockRepository(); + IAssessmentSection assessmentSectionStub = mockRepository.Stub(); + IGui guiStub = mockRepository.Stub(); + IMainWindow windowsStub = mockRepository.Stub(); + guiStub.Stub(gs => gs.MainWindow).Return(windowsStub); + mockRepository.ReplayAll(); + + var data = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext(new ObservableList(), assessmentSectionStub); + Plugin.Gui = guiStub; + Plugin.Activate(); + + using (var view = CreateView()) { - return typeof(GrassCoverErosionOutwardsDesignWaterLevelLocationsContext); + Info.AfterCreate(view, data); + + // Assert + Assert.AreSame(assessmentSectionStub, view.AssessmentSection); + Assert.AreSame(guiStub, view.ApplicationSelection); + Assert.IsInstanceOf(view.CalculationGuiService); } + + mockRepository.VerifyAll(); } - protected override Type ViewDataType + public GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest() { - get - { - return typeof(IEnumerable); - - } + DataType = typeof(GrassCoverErosionOutwardsDesignWaterLevelLocationsContext); + ViewDataType = typeof(IEnumerable); + ViewIcon = RingtoetsCommonFormsResources.GenericInputOutputIcon; + ViewName = Resources.GrassCoverErosionOutwardsWaterLevelLocations_DisplayName; } + protected override GrassCoverErosionOutwardsDesignWaterLevelLocationsView CreateView() + { + return new GrassCoverErosionOutwardsDesignWaterLevelLocationsView(); + } + protected override PluginBase CreatePlugin() { return new GrassCoverErosionOutwardsPlugin(); } } - public abstract class ViewInfoTest + public abstract class ViewInfoTest where TView : IDisposable { - private PluginBase plugin; - private ViewInfo Info { get; set; } + protected Type DataType; + protected Type ViewDataType; + protected Image ViewIcon; + protected string ViewName; + protected PluginBase Plugin; - protected abstract Type DataType { get; } - protected abstract Type ViewDataType { get; } - [SetUp] public void SetUp() { - plugin = CreatePlugin(); - Info = plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(TView)); + Plugin = CreatePlugin(); + Info = Plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(TView)); + if (ViewDataType == null) + { + ViewDataType = DataType; + } } [TearDown] public void TearDown() { - plugin.Dispose(); + Plugin.Dispose(); } [TestCase] public void Initialized_Always_DataTypeAndViewTypeAsExpected() { Assert.NotNull(Info, "Expected a viewInfo definition for views with type {0}.", typeof(TView)); Assert.AreEqual(DataType, Info.DataType); + Assert.AreEqual(ViewDataType, Info.ViewDataType); } - protected virtual PluginBase CreatePlugin() + [Test] + public void ViewType_Always_ReturnsViewType() { - return null; + // Call + var expectedViewType = Info.ViewType; + + // Assert + Assert.AreEqual(typeof(TView), expectedViewType); } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + var expectedDataType = Info.DataType; + + // Assert + Assert.AreEqual(DataType, expectedDataType); + } + + [Test] + public void ViewDataType_Always_ReturnsViewDataType() + { + // Call + Type expectedViewDataType = Info.ViewDataType; + + // Assert + Assert.AreEqual(ViewDataType, expectedViewDataType); + } + + [Test] + public void Image_Always_ReturnsViewIcon() + { + // Call + Image image = Info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(ViewIcon, image); + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Setup + using (var view = CreateView()) + { + // Call + var expectedViewName = Info.GetViewName(view, null); + + // Assert + Assert.AreEqual(ViewName, expectedViewName); + } + } + + [Test] + [TestCaseSource("CloseForDataTests")] + public void CloseForData_ForDifferentObjects_ReturnsExpectedValue(CloseForDataTest test) + { + using (var view = CreateView()) + { + // Call + var closeForData = Info.CloseForData(view, test.DataToCloseFor); + + // Assert + Assert.AreEqual(test.ExpectedResult, closeForData); + } + } + + protected virtual IEnumerable CloseForDataTests + { + get + { + return new[] + { + new CloseForDataTest() + }; + } + } + + protected abstract PluginBase CreatePlugin(); + protected abstract GrassCoverErosionOutwardsDesignWaterLevelLocationsView CreateView(); + protected ViewInfo Info { get; private set; } + + public class CloseForDataTest + { + public bool ExpectedResult { get; set; } + public object DataToCloseFor { get; set; } + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsResultViewInfoTest.cs =================================================================== diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -rbe9ffe357aaf542c7bcec7f32929028081223566 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsResultViewInfoTest.cs (.../GrassCoverErosionOutwardsResultViewInfoTest.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsResultViewInfoTest.cs (.../GrassCoverErosionOutwardsResultViewInfoTest.cs) (revision be9ffe357aaf542c7bcec7f32929028081223566) @@ -80,11 +80,10 @@ public void GetViewName_Always_ReturnsViewName() { // Setup - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); using (var view = new GrassCoverErosionOutwardsFailureMechanismResultView()) { // Call - var viewName = info.GetViewName(view, failureMechanism.SectionResults); + var viewName = info.GetViewName(view, null); // Assert Assert.AreEqual("Resultaat", viewName);