Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/DuneErosionFailureMechanismPropertyChangeHandler.cs =================================================================== diff -u --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/DuneErosionFailureMechanismPropertyChangeHandler.cs (revision 0) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/DuneErosionFailureMechanismPropertyChangeHandler.cs (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -0,0 +1,65 @@ +// 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.Linq; +using Core.Common.Base; +using Ringtoets.Common.Forms; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Forms.Properties; +using Ringtoets.DuneErosion.Service; + +namespace Ringtoets.DuneErosion.Forms +{ + /// + /// Class that handles changes to the data model at failure mechanism level of + /// . + /// + public class DuneErosionFailureMechanismPropertyChangeHandler : FailureMechanismPropertyChangeHandler + { + protected override string ConfirmationMessage + { + get + { + return Resources.DuneErosionFailureMechanismPropertyChangeHandler_Confirm_change_and_clearing_dune_locations; + } + } + + protected override bool RequiresConfirmation(DuneErosionFailureMechanism failureMechanism) + { + return base.RequiresConfirmation(failureMechanism) || + failureMechanism.DuneLocations.Any(c => c.Output != null); + } + + protected override IEnumerable PropertyChanged(DuneErosionFailureMechanism failureMechanism) + { + var affectedObjects = new List(base.PropertyChanged(failureMechanism)); + + IEnumerable affectedLocations = DuneErosionDataSynchronizationService.ClearDuneLocationOutput(failureMechanism.DuneLocations); + + if (affectedLocations.Any()) + { + affectedObjects.Add(failureMechanism.DuneLocations); + } + return affectedObjects; + } + } +} \ No newline at end of file Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rc824c971119bfdb785a6b1641a821fe344f22869 -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c824c971119bfdb785a6b1641a821fe344f22869) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -82,6 +82,18 @@ } /// + /// Looks up a localized string similar to Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle randvoorwaarden locaties in dit toetsspoor verwijderd worden. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + internal static string DuneErosionFailureMechanismPropertyChangeHandler_Confirm_change_and_clearing_dune_locations { + get { + return ResourceManager.GetString("DuneErosionFailureMechanismPropertyChangeHandler_Confirm_change_and_clearing_dune" + + "_locations", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Nummer van het kustvak waar de locatie onderdeel van uitmaakt.. /// internal static string DuneLocation_CoastalAreaId_Description { Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx =================================================================== diff -u -rc824c971119bfdb785a6b1641a821fe344f22869 -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx (.../Resources.resx) (revision c824c971119bfdb785a6b1641a821fe344f22869) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Properties/Resources.resx (.../Resources.resx) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -117,6 +117,11 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle randvoorwaarden locaties in dit toetsspoor verwijderd worden. + +Weet u zeker dat u wilt doorgaan? + Nummer van het kustvak waar de locatie onderdeel van uitmaakt. Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj =================================================================== diff -u -r74d8d838a60411ed1566f8afbd0003c1b9cf86cf -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 74d8d838a60411ed1566f8afbd0003c1b9cf86cf) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -43,6 +43,7 @@ Properties\GlobalAssembly.cs + @@ -130,6 +131,11 @@ Ringtoets.DuneErosion.Data False + + {fdee3429-0bb1-4ad2-813a-06fad425ea6f} + Ringtoets.DuneErosion.Service + False + Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs =================================================================== diff -u -r74d8d838a60411ed1566f8afbd0003c1b9cf86cf -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 74d8d838a60411ed1566f8afbd0003c1b9cf86cf) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Plugin/DuneErosionPlugin.cs (.../DuneErosionPlugin.cs) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -34,6 +34,7 @@ using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Forms; using Ringtoets.DuneErosion.Forms.PresentationObjects; using Ringtoets.DuneErosion.Forms.PropertyClasses; using Ringtoets.DuneErosion.Forms.Views; @@ -55,7 +56,7 @@ yield return new PropertyInfo { CreateInstance = context => new DuneErosionFailureMechanismProperties(context.WrappedData, - new FailureMechanismPropertyChangeHandler()) + new DuneErosionFailureMechanismPropertyChangeHandler()) }; yield return new PropertyInfo { Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/DuneErosionFailureMechanismPropertyChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/DuneErosionFailureMechanismPropertyChangeHandlerTest.cs (revision 0) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/DuneErosionFailureMechanismPropertyChangeHandlerTest.cs (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -0,0 +1,251 @@ +// 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; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; + +namespace Ringtoets.DuneErosion.Forms.Test +{ + [TestFixture] + public class DuneErosionFailureMechanismPropertyChangeHandlerTest : NUnitFormTest + { + [Test] + public void SetPropertyValueAfterConfirmation_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Setup + var changeHandler = new DuneErosionFailureMechanismPropertyChangeHandler(); + + // Call + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + null, + 3, + (f, v) => { }); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void SetPropertyValueAfterConfirmation_WithoutValue_ThrowsArgumentNullException() + { + // Setup + var changeHandler = new DuneErosionFailureMechanismPropertyChangeHandler(); + + // Call + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + new DuneErosionFailureMechanism(), + null, + (f, v) => { }); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("value", paramName); + } + + [Test] + public void SetPropertyValueAfterConfirmation_WithoutSetProperty_ThrowsArgumentNullException() + { + // Setup + var changeHandler = new DuneErosionFailureMechanismPropertyChangeHandler(); + + // Call + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + new DuneErosionFailureMechanism(), + 3, + null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("setValue", paramName); + } + + [Test] + [TestCaseSource(nameof(ChangePropertyTestCases))] + public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_MessageDialogShownSetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase) + { + // Setup + bool dialogBoxWillBeShown = testCase.ExpectedAffectedLocations.Any(); + + string title = ""; + string message = ""; + if (dialogBoxWillBeShown) + { + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + title = tester.Title; + message = tester.Text; + + tester.ClickOk(); + }; + } + + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.DuneLocations.AddRange(testCase.Locations); + + var propertySet = 0; + + var changeHandler = new DuneErosionFailureMechanismPropertyChangeHandler(); + + // Call + var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + failureMechanism, + 3, + (f, v) => propertySet++); + + // Assert + if (dialogBoxWillBeShown) + { + Assert.AreEqual("Bevestigen", title); + string expectedMessage = "Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle randvoorwaarden locaties in dit toetsspoor verwijderd worden." + Environment.NewLine + + Environment.NewLine + + "Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, message); + } + Assert.AreEqual(1, propertySet); + var expectedAffectedObjects = new List(new[] + { + failureMechanism + }); + if (testCase.ExpectedAffectedLocations.Any()) + { + expectedAffectedObjects.Add(failureMechanism.DuneLocations); + } + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickCancel(); + }; + + var failureMechanism = new DuneErosionFailureMechanism(); + failureMechanism.DuneLocations.Add(CreateDuneLocationWithoutOutput()); + failureMechanism.DuneLocations.Add(CreateDuneLocationWithOutput()); + + var propertySet = 0; + + var changeHandler = new DuneErosionFailureMechanismPropertyChangeHandler(); + + // Call + var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + failureMechanism, + 3, + (f, v) => propertySet++); + + // Assert + Assert.AreEqual(0, propertySet); + CollectionAssert.IsEmpty(affectedObjects); + } + + public class ChangePropertyTestCase + { + public ChangePropertyTestCase(ICollection locations) + { + Locations = locations; + ExpectedAffectedLocations = locations.Where(c => c.Output != null).ToArray(); + } + + public ICollection Locations { get; } + public ICollection ExpectedAffectedLocations { get; } + } + + private static IEnumerable ChangePropertyTestCases() + { + yield return new TestCaseData( + new ChangePropertyTestCase(new TestDuneLocation[0]) + ).SetName("SetPropertyValueAfterConfirmation No locations"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithoutOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Single location without output"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Single location with output"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithoutOutput(), + CreateDuneLocationWithoutOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Two locations without output"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithOutput(), + CreateDuneLocationWithoutOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Location with and location without output"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithOutput(), + CreateDuneLocationWithOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Two locations with output"); + + yield return new TestCaseData( + new ChangePropertyTestCase(new[] + { + CreateDuneLocationWithOutput(), + CreateDuneLocationWithoutOutput(), + CreateDuneLocationWithOutput() + }) + ).SetName("SetPropertyValueAfterConfirmation Two locations with and one location without output"); + } + + private static DuneLocation CreateDuneLocationWithoutOutput() + { + return new TestDuneLocation(); + } + + private static DuneLocation CreateDuneLocationWithOutput() + { + return new TestDuneLocation + { + Output = new TestDuneLocationOutput() + }; + } + } +} \ No newline at end of file Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj =================================================================== diff -u -r74d8d838a60411ed1566f8afbd0003c1b9cf86cf -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision 74d8d838a60411ed1566f8afbd0003c1b9cf86cf) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/Ringtoets.DuneErosion.Forms.Test.csproj (.../Ringtoets.DuneErosion.Forms.Test.csproj) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -57,6 +57,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs =================================================================== diff -u -re853e0f8c9bfa09ee56ce3e323d82b1d42446e02 -r33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs) (revision e853e0f8c9bfa09ee56ce3e323d82b1d42446e02) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs) (revision 33996c939c8044f0e09d8b1f1ef69b5b5b1e28c3) @@ -165,12 +165,12 @@ ExpectedAffectedLocations = locations.Where(c => c.DesignWaterLevelOutput != null || c.WaveHeightOutput != null).ToArray(); } - public ICollection Locations { get; private set; } - public ICollection ExpectedAffectedLocations { get; private set; } + public ICollection Locations { get; } + public ICollection ExpectedAffectedLocations { get; } - public ICollection Calculations { get; private set; } + public ICollection Calculations { get; } - public ICollection ExpectedAffectedCalculations { get; private set; } + public ICollection ExpectedAffectedCalculations { get; } } static IEnumerable ChangePropertyTestCases()