Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs =================================================================== diff -u -r51d8e744ffb2168ca56ca4b6260ad9c2590c0170 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision 51d8e744ffb2168ca56ca4b6260ad9c2590c0170) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/HydraulicBoundaryLocationsView.cs (.../HydraulicBoundaryLocationsView.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -27,6 +27,7 @@ using Core.Common.Gui.Selection; using Core.Common.Utils.Extensions; using Core.Common.Utils.Reflection; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.GuiServices; using Ringtoets.HydraRing.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -71,6 +72,8 @@ /// public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; } + public abstract IAssessmentSection AssessmentSection { get; set; } + public virtual object Data { get Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/WaveHeightLocationRow.cs =================================================================== diff -u -raa8007e0a07c5ab485633583aa095ea34baf1a49 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/WaveHeightLocationRow.cs (.../WaveHeightLocationRow.cs) (revision aa8007e0a07c5ab485633583aa095ea34baf1a49) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/WaveHeightLocationRow.cs (.../WaveHeightLocationRow.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -36,7 +36,7 @@ /// /// Creates a new instance of . /// - /// The for this row. + /// The for this row. /// Thrown when is null. public WaveHeightLocationRow(HydraulicBoundaryLocation hydraulicBoundaryLocation) : base(hydraulicBoundaryLocation) { } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs =================================================================== diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -438,6 +438,7 @@ } public IEnumerable LocationsToCalculate { get; private set; } + public override IAssessmentSection AssessmentSection { get; set; } public object CreateForSelection { get; set; } protected override TestHydraulicBoundaryLocationRow CreateNewRow(HydraulicBoundaryLocation location) Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs =================================================================== diff -u -r46432103d5b2ecb86593d5df7e90de78a1815314 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision 46432103d5b2ecb86593d5df7e90de78a1815314) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsView.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -48,8 +48,9 @@ } set { - base.Data = value; - hydraulicBoundaryLocationsObserver.Observable = value as IObservable; + var data = (IObservable) value; + base.Data = data; + hydraulicBoundaryLocationsObserver.Observable = data; } } @@ -58,7 +59,7 @@ return new DesignWaterLevelLocationRow(location); } - public IAssessmentSection AssessmentSection { get; set; } + public override IAssessmentSection AssessmentSection { get; set; } protected override void InitializeDataGridView() { Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs =================================================================== diff -u -r46432103d5b2ecb86593d5df7e90de78a1815314 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsView.cs) (revision 46432103d5b2ecb86593d5df7e90de78a1815314) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsWaveHeightLocationsView.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsView.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -33,7 +33,7 @@ { /// /// View for the with - /// + /// for the public class GrassCoverErosionOutwardsWaveHeightLocationsView : HydraulicBoundaryLocationsView { private readonly Observer hydraulicBoundaryLocationObserver; @@ -54,12 +54,13 @@ } set { - base.Data = value; - hydraulicBoundaryLocationObserver.Observable = value as IObservable; + var data = (IObservable) value; + base.Data = data; + hydraulicBoundaryLocationObserver.Observable = data; } } - public IAssessmentSection AssessmentSection { get; set; } + public override IAssessmentSection AssessmentSection { get; set; } protected override WaveHeightLocationRow CreateNewRow(HydraulicBoundaryLocation location) { Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -rb96f2e7a668c663c44150fcc3045edebb3ad56e9 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision b96f2e7a668c663c44150fcc3045edebb3ad56e9) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -126,7 +126,7 @@ IEnumerable, GrassCoverErosionOutwardsWaveHeightLocationsView> { - GetViewName = (v, o) => RingtoetsGrassCoverErosionOutwardsFormsResources.GrassCoverErosionOutwardsHydraulicBoundaryLocation_WaveHeight_DisplayName, + GetViewName = (v, o) => RingtoetsGrassCoverErosionOutwardsFormsResources.GrassCoverErosionOutwardsWaveHeightLocationsContext_DisplayName, GetViewData = context => context.WrappedData, CloseForData = CloseGrassCoverErosionOutwardsLocationsViewForData, Image = RingtoetsCommonFormsResources.GenericInputOutputIcon, @@ -317,18 +317,36 @@ { var section = dataToCloseFor as IAssessmentSection; var failureMechanismContext = dataToCloseFor as GrassCoverErosionOutwardsFailureMechanismContext; - var viewAssessmentSection = view.AssessmentSection; - var closeForFailureMechanism = failureMechanismContext != null && ReferenceEquals(failureMechanismContext.Parent, viewAssessmentSection); - var closeForSection = section != null && ReferenceEquals(section, viewAssessmentSection); - return closeForSection || closeForFailureMechanism; + return CloseForSectionOrForFailureMechanism(section, viewAssessmentSection, failureMechanismContext); } #endregion + #region: CloseDesignWaterLevelLocationsViewForData + private static bool CloseDesignWaterLevelLocationsViewForData(GrassCoverErosionOutwardsDesignWaterLevelLocationsView view, object dataToCloseFor) + { + var section = dataToCloseFor as IAssessmentSection; + var failureMechanismContext = dataToCloseFor as GrassCoverErosionOutwardsFailureMechanismContext; + var viewAssessmentSection = view.AssessmentSection; + + return CloseForSectionOrForFailureMechanism(section, viewAssessmentSection, failureMechanismContext); + } #endregion + private static bool CloseForSectionOrForFailureMechanism(IAssessmentSection sectionToCloseFor, + IAssessmentSection viewAssessmentSection, + GrassCoverErosionOutwardsFailureMechanismContext failureMechanismContext) + { + var closeForFailureMechanism = failureMechanismContext != null && ReferenceEquals(failureMechanismContext.Parent, viewAssessmentSection); + var closeForSection = sectionToCloseFor != null && ReferenceEquals(sectionToCloseFor, viewAssessmentSection); + + + return closeForSection || closeForFailureMechanism; + } + + #endregion #region TreeNodeInfos #region GrassCoverErosionOutwardsFailureMechanismContext TreeNodeInfo @@ -476,18 +494,8 @@ .Build(); } - private bool CloseDesignWaterLevelLocationsViewForData(GrassCoverErosionOutwardsDesignWaterLevelLocationsView view, object dataToCloseFor) - { - var section = dataToCloseFor as IAssessmentSection; - var failureMechanismContext = dataToCloseFor as GrassCoverErosionOutwardsFailureMechanismContext; - var viewAssessmentSection = view.AssessmentSection; - var closeForFailureMechanism = failureMechanismContext != null && ReferenceEquals(failureMechanismContext.Parent, viewAssessmentSection); - var closeForSection = section != null && ReferenceEquals(section, viewAssessmentSection); - return closeForSection || closeForFailureMechanism; - } - #endregion #region GrassCoverErosionOutwardsWaveHeightLocationsContext TreeNodeInfo Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r46432103d5b2ecb86593d5df7e90de78a1815314 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 46432103d5b2ecb86593d5df7e90de78a1815314) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -110,7 +111,32 @@ Assert.IsFalse(button.Enabled); } + [Test] + public void WaveHeightLocationsView_WithNonIObservableList_ThrowsInvalidCastException() + { + // Setup + var view = ShowDesignWaterLevelLocationsView(); + + List locations = new List(); + locations.Add(new HydraulicBoundaryLocation(1, "1", 1.0, 1.0)); + locations.Add(new HydraulicBoundaryLocation(2, "2", 2.0, 2.0) + { + WaveHeight = (RoundedDouble)1.23 + }); + locations.Add(new HydraulicBoundaryLocation(3, "3", 3.0, 3.0) + { + DesignWaterLevel = (RoundedDouble)2.45 + }); + + // Call + TestDelegate action = () => view.Data = locations; + + // Assert + Assert.Throws(action); + } + + [Test] public void DesignWaterLevelLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup & Call Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs =================================================================== diff -u -r46432103d5b2ecb86593d5df7e90de78a1815314 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 46432103d5b2ecb86593d5df7e90de78a1815314) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -107,6 +108,30 @@ } [Test] + public void WaveHeightLocationsView_WithNonIObservableList_ThrowsInvalidCastException() + { + // Setup + var view = ShowWaveHeightLocationsView(); + + List locations = new List(); + locations.Add(new HydraulicBoundaryLocation(1, "1", 1.0, 1.0)); + locations.Add(new HydraulicBoundaryLocation(2, "2", 2.0, 2.0) + { + WaveHeight = (RoundedDouble)1.23 + }); + locations.Add(new HydraulicBoundaryLocation(3, "3", 3.0, 3.0) + { + DesignWaterLevel = (RoundedDouble)2.45 + }); + + // Call + TestDelegate action = () => view.Data = locations; + + // Assert + Assert.Throws(action); + } + + [Test] public void WaveHeightLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { // Setup & Call Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs =================================================================== diff -u -raa8007e0a07c5ab485633583aa095ea34baf1a49 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision aa8007e0a07c5ab485633583aa095ea34baf1a49) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -25,12 +25,12 @@ using Core.Common.Gui; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; -using Core.Common.Gui.TestUtil; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; using Ringtoets.GrassCoverErosionOutwards.Forms.Views; @@ -54,7 +54,7 @@ Assert.AreEqual(typeof(IEnumerable), info.ViewDataType); Assert.AreEqual(typeof(GrassCoverErosionOutwardsWaveHeightLocationsView), info.ViewType); TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, info.Image); - Assert.AreEqual(Resources.GrassCoverErosionOutwardsHydraulicBoundaryLocation_WaveHeight_DisplayName, info.GetViewName(null, null)); + Assert.AreEqual(Resources.GrassCoverErosionOutwardsWaveHeightLocationsContext_DisplayName, info.GetViewName(null, null)); } } @@ -88,6 +88,149 @@ mockRepository.VerifyAll(); } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSection; + + // Call + var closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingFailureMechanismContext_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSection; + + // Call + var closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingFailureMechanismContext_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionB); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.AssessmentSection = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + view.Data = assessmentSectionA; + + // Call + var closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ViewDataNull_ReturnsFalse() + { + // Setup + using (var view = new GrassCoverErosionOutwardsWaveHeightLocationsView()) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + var info = GetInfo(plugin); + + // Call + var closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + } + private ViewInfo GetInfo(PluginBase plugin) { return plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(GrassCoverErosionOutwardsWaveHeightLocationsView)); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs =================================================================== diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs (.../DesignWaterLevelLocationsView.cs) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/DesignWaterLevelLocationsView.cs (.../DesignWaterLevelLocationsView.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -51,7 +51,7 @@ hydraulicBoundaryDatabaseObserver = new Observer(() => dataGridViewControl.RefreshDataGridView()); } - public IAssessmentSection AssessmentSection + public override IAssessmentSection AssessmentSection { get { Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs =================================================================== diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -ra50b5199ff7097db5e96948c4e192b5fef0e9f92 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision a50b5199ff7097db5e96948c4e192b5fef0e9f92) @@ -51,7 +51,7 @@ hydraulicBoundaryDatabaseObserver = new Observer(() => dataGridViewControl.RefreshDataGridView()); } - public IAssessmentSection AssessmentSection + public override IAssessmentSection AssessmentSection { get {