Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -r953e0d229cccbaea58fd9e9ef582504b9fa0cf7c -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 953e0d229cccbaea58fd9e9ef582504b9fa0cf7c) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -116,7 +116,7 @@ "traject_6-3.shx")) { var importer = new ReferenceLineImporter(demoAssessmentSection.ReferenceLine, - new ReferenceLineReplacementHandler(demoAssessmentSection, viewCommands), + new ReferenceLineUpdateHandler(demoAssessmentSection, viewCommands), Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3.shp")); importer.Import(); Fisheye: Tag e949ab20d487bf97ab1cedf2b360fdb1f948419f refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/IReferenceLineReplaceHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/IReferenceLineUpdateHandler.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/IReferenceLineUpdateHandler.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/IReferenceLineUpdateHandler.cs (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -0,0 +1,57 @@ +// Copyright (C) Stichting Deltares 2018. 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.Generic; +using Core.Common.Base; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Ringtoets.Common.IO.ReferenceLines +{ + /// + /// Interface for an object that can properly replace a + /// from an . + /// + public interface IReferenceLineUpdateHandler + { + /// + /// Checks to see if the replacement of the should occur + /// or not. + /// + /// true if the replacement should occur, false otherwise. + bool ConfirmReplace(); + + /// + /// Replaces the of a + /// and propagates the changes to underlying data structure. + /// + /// The reference line to be updated. + /// The new reference line. + /// All objects that have been affected by the replacement. + /// Thrown when any parameter is null. + IEnumerable Replace(ReferenceLine originalReferenceLine, ReferenceLine newReferenceLine); + + /// + /// Perform post-replacement updates. + /// + void DoPostReplacementUpdates(); + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs =================================================================== diff -u -r00b160ed6c781f5f20b3697143c255fc498b0ef1 -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 00b160ed6c781f5f20b3697143c255fc498b0ef1) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -36,7 +36,7 @@ public class ReferenceLineImporter : FileImporterBase { private readonly List changedObservables = new List(); - private readonly IReferenceLineReplaceHandler replacementHandler; + private readonly IReferenceLineUpdateHandler replacementHandler; /// /// Initializes a new instance of the class. @@ -48,7 +48,7 @@ /// Thrown when /// or is null. public ReferenceLineImporter(ReferenceLine importTarget, - IReferenceLineReplaceHandler replacementHandler, + IReferenceLineUpdateHandler replacementHandler, string filePath) : base(filePath, importTarget) { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -raad074a1117fdd6eb1a371e2778e81263087cd0a -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision aad074a1117fdd6eb1a371e2778e81263087cd0a) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -83,7 +83,7 @@ Resources.resx - + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs =================================================================== diff -u -r2aa1dd011d1580be5236b2477496f8e7adb1a12e -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 2aa1dd011d1580be5236b2477496f8e7adb1a12e) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -741,7 +741,7 @@ var referenceLine = new ReferenceLine(); var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); handler.Stub(h => h.ConfirmReplace()).Return(true); handler.Stub(h => h.Replace(Arg.Is.NotNull, Arg.Is.NotNull)) Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs =================================================================== diff -u -r4f0a2be792d13dd811a5f500f8dc3cbba5513d14 -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision 4f0a2be792d13dd811a5f500f8dc3cbba5513d14) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -42,7 +42,7 @@ public void Constructor_ReferenceLineNull_ThrowArgumentNullException() { var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); mocks.ReplayAll(); // Call @@ -59,7 +59,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); mocks.ReplayAll(); // Call @@ -75,7 +75,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.Replace(Arg.Is.NotNull, Arg.Is.NotNull)) .WhenCalled(invocation => @@ -107,7 +107,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); handler.Expect(h => h.Replace(Arg.Is.NotNull, Arg.Is.NotNull)) .Return(Enumerable.Empty()); @@ -154,7 +154,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) .Repeat.Never(); handler.Expect(h => h.Replace(null, null)) @@ -183,7 +183,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) .Repeat.Never(); handler.Expect(h => h.Replace(null, null)) @@ -212,7 +212,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()).Return(false); handler.Expect(h => h.Replace(null, null)) .IgnoreArguments() @@ -240,7 +240,7 @@ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); var importer = new ReferenceLineImporter(ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), handler, path); handler.Expect(h => h.ConfirmReplace()) .WhenCalled(invocation => importer.Cancel()) @@ -268,7 +268,7 @@ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); handler.Stub(h => h.ConfirmReplace()) .Return(true); mocks.ReplayAll(); @@ -300,7 +300,7 @@ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler = mocks.Stub(); handler.Stub(h => h.ConfirmReplace()) .Return(true); handler.Stub(h => h.Replace(Arg.Is.NotNull, @@ -334,7 +334,7 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()) .Repeat.Never(); handler.Expect(h => h.Replace(Arg.Is.NotNull, @@ -385,7 +385,7 @@ var observable2 = mocks.StrictMock(); observable2.Expect(o => o.NotifyObservers()); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); handler.Expect(h => h.ConfirmReplace()).Return(true); handler.Expect(h => h.Replace(Arg.Is.Same(referenceLine), Arg.Is.NotNull)) @@ -421,7 +421,7 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - var handler = mocks.StrictMock(); + var handler = mocks.StrictMock(); var importer = new ReferenceLineImporter(referenceLine, handler, path); handler.Expect(h => h.ConfirmReplace()) .WhenCalled(invocation => importer.Cancel()) @@ -460,7 +460,7 @@ var observable2 = mocks.StrictMock(); observable2.Expect(o => o.NotifyObservers()); - var handler = mocks.Stub(); + var handler = mocks.Stub(); handler.Stub(h => h.ConfirmReplace()).Return(true); handler.Expect(h => h.Replace(Arg.Is.Same(referenceLine), Arg.Is.NotNull)) Fisheye: Tag e949ab20d487bf97ab1cedf2b360fdb1f948419f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/ReferenceLineReplacementHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2018. 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.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Gui.Commands; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.IO.ReferenceLines; +using Ringtoets.Common.Service; +using Ringtoets.Integration.Plugin.Properties; +using Ringtoets.Integration.Service; +using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Handlers +{ + /// + /// Class responsible for replacing a on a . + /// + public class ReferenceLineUpdateHandler : IReferenceLineUpdateHandler + { + private readonly IAssessmentSection assessmentSection; + private readonly IViewCommands viewCommands; + private readonly Queue removedObjects = new Queue(); + + /// + /// Creates a new instance of . + /// + /// The assessment section to remove data for. + /// The view commands used to close views for removed data. + /// Thrown when any parameter is null. + public ReferenceLineUpdateHandler(IAssessmentSection assessmentSection, IViewCommands viewCommands) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (viewCommands == null) + { + throw new ArgumentNullException(nameof(viewCommands)); + } + + this.assessmentSection = assessmentSection; + this.viewCommands = viewCommands; + } + + public bool ConfirmReplace() + { + DialogResult result = MessageBox.Show(Resources.ReferenceLineReplacementHandler_Confirm_clear_referenceLine_dependent_data, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + return result == DialogResult.OK; + } + + public IEnumerable Replace(ReferenceLine originalReferenceLine, ReferenceLine newReferenceLine) + { + if (originalReferenceLine == null) + { + throw new ArgumentNullException(nameof(originalReferenceLine)); + } + + if (newReferenceLine == null) + { + throw new ArgumentNullException(nameof(newReferenceLine)); + } + + removedObjects.Clear(); + + ClearResults results = RingtoetsDataSynchronizationService.ClearReferenceLineDependentData(assessmentSection); + foreach (object removedObject in results.RemovedObjects) + { + removedObjects.Enqueue(removedObject); + } + + originalReferenceLine.SetGeometry(newReferenceLine.Points); + return results.ChangedObjects; + } + + public void DoPostReplacementUpdates() + { + while (removedObjects.Count > 0) + { + viewCommands.RemoveAllViewsForItem(removedObjects.Dequeue()); + } + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj =================================================================== diff -u -r1b06b4edc3ec9567e5550e6f66efcae7ce51a97f -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 1b06b4edc3ec9567e5550e6f66efcae7ce51a97f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -40,7 +40,7 @@ - + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r953e0d229cccbaea58fd9e9ef582504b9fa0cf7c -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 953e0d229cccbaea58fd9e9ef582504b9fa0cf7c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -722,7 +722,7 @@ FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, RingtoetsCommonIOResources.Shape_file_filter_Description), CreateFileImporter = (context, filePath) => new ReferenceLineImporter(context.WrappedData, - new ReferenceLineReplacementHandler(context.AssessmentSection, Gui.ViewCommands), + new ReferenceLineUpdateHandler(context.AssessmentSection, Gui.ViewCommands), filePath) }; Fisheye: Tag e949ab20d487bf97ab1cedf2b360fdb1f948419f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineReplacementHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineUpdateHandlerTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineUpdateHandlerTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/ReferenceLineUpdateHandlerTest.cs (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -0,0 +1,435 @@ +// Copyright (C) Stichting Deltares 2018. 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.Linq; +using Core.Common.Base; +using Core.Common.Gui.Commands; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.ReferenceLines; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Integration.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.Piping.Data; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.WaveImpactAsphaltCover.Data; + +namespace Ringtoets.Integration.Plugin.Test.Handlers +{ + [TestFixture] + public class ReferenceLineUpdateHandlerTest : NUnitFormTest + { + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new ReferenceLineUpdateHandler(null, viewCommands); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_ViewCommandsNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new ReferenceLineUpdateHandler(assessmentSection, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("viewCommands", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + // Assert + Assert.IsInstanceOf(handler); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ConfirmReplace_ClickDialog_ReturnTrueIfOkAndFalseIfCancel(bool clickOk) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + string dialogTitle = null, dialogMessage = null; + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + dialogTitle = tester.Title; + dialogMessage = tester.Text; + if (clickOk) + { + tester.ClickOk(); + } + else + { + tester.ClickCancel(); + } + }; + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + // Call + bool result = handler.ConfirmReplace(); + + // Assert + Assert.AreEqual(clickOk, result); + + Assert.AreEqual("Bevestigen", dialogTitle); + Assert.AreEqual("Na het importeren van een aangepaste ligging van de referentielijn zullen alle geïmporteerde en berekende gegevens van alle toetssporen worden gewist." + Environment.NewLine + + Environment.NewLine + + "Wilt u doorgaan?", + dialogMessage); + mocks.VerifyAll(); + } + + [Test] + public void Replace_OriginalReferenceLineNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + var referenceLine = new ReferenceLine(); + + // Call + TestDelegate call = () => handler.Replace(null, referenceLine); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("originalReferenceLine", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Replace_NewReferenceLineNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + var referenceLine = new ReferenceLine(); + + // Call + TestDelegate call = () => handler.Replace(referenceLine, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("newReferenceLine", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Replace_FullyConfiguredAssessmentSection_AllReferenceLineDependentDataCleared() + { + // Setup + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + ReferenceLine referenceLine = ReferenceLineTestFactory.CreateReferenceLineWithGeometry(); + + // Call + IObservable[] observables = handler.Replace(assessmentSection.ReferenceLine, referenceLine).ToArray(); + + // Assert + Assert.AreEqual(59, observables.Length); + + PipingFailureMechanism pipingFailureMechanism = assessmentSection.Piping; + CollectionAssert.IsEmpty(pipingFailureMechanism.Sections); + CollectionAssert.IsEmpty(pipingFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, pipingFailureMechanism); + CollectionAssert.Contains(observables, pipingFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(pipingFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, pipingFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(pipingFailureMechanism.StochasticSoilModels); + CollectionAssert.Contains(observables, pipingFailureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(pipingFailureMechanism.SurfaceLines); + CollectionAssert.Contains(observables, pipingFailureMechanism.SurfaceLines); + + GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwardsFailureMechanism = assessmentSection.GrassCoverErosionInwards; + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, grassCoverErosionInwardsFailureMechanism); + CollectionAssert.Contains(observables, grassCoverErosionInwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, grassCoverErosionInwardsFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.DikeProfiles); + CollectionAssert.Contains(observables, grassCoverErosionInwardsFailureMechanism.DikeProfiles); + + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, grassCoverErosionOutwardsFailureMechanism); + CollectionAssert.Contains(observables, grassCoverErosionOutwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.Contains(observables, grassCoverErosionOutwardsFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles); + + WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism = assessmentSection.WaveImpactAsphaltCover; + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, waveImpactAsphaltCoverFailureMechanism); + CollectionAssert.Contains(observables, waveImpactAsphaltCoverFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.Contains(observables, waveImpactAsphaltCoverFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles); + + StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism = assessmentSection.StabilityStoneCover; + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, stabilityStoneCoverFailureMechanism); + CollectionAssert.Contains(observables, stabilityStoneCoverFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.Contains(observables, stabilityStoneCoverFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, stabilityStoneCoverFailureMechanism.ForeshoreProfiles); + + ClosingStructuresFailureMechanism closingStructuresFailureMechanism = assessmentSection.ClosingStructures; + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, closingStructuresFailureMechanism); + CollectionAssert.Contains(observables, closingStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, closingStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, closingStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.ClosingStructures); + CollectionAssert.Contains(observables, closingStructuresFailureMechanism.ClosingStructures); + + HeightStructuresFailureMechanism heightStructuresFailureMechanism = assessmentSection.HeightStructures; + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, heightStructuresFailureMechanism); + CollectionAssert.Contains(observables, heightStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, heightStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, heightStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.HeightStructures); + CollectionAssert.Contains(observables, heightStructuresFailureMechanism.HeightStructures); + + StabilityPointStructuresFailureMechanism stabilityPointStructuresFailureMechanism = assessmentSection.StabilityPointStructures; + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism); + CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.StabilityPointStructures); + CollectionAssert.Contains(observables, stabilityPointStructuresFailureMechanism.StabilityPointStructures); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + CollectionAssert.IsEmpty(duneErosionFailureMechanism.Sections); + CollectionAssert.IsEmpty(duneErosionFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, duneErosionFailureMechanism); + CollectionAssert.Contains(observables, duneErosionFailureMechanism.SectionResults); + + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = assessmentSection.MacroStabilityInwards; + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, macroStabilityInwardsFailureMechanism); + CollectionAssert.Contains(observables, macroStabilityInwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.CalculationsGroup.Children); + CollectionAssert.Contains(observables, macroStabilityInwardsFailureMechanism.CalculationsGroup); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.StochasticSoilModels); + CollectionAssert.Contains(observables, macroStabilityInwardsFailureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.SurfaceLines); + CollectionAssert.Contains(observables, macroStabilityInwardsFailureMechanism.SurfaceLines); + + MacroStabilityOutwardsFailureMechanism macroStabilityOutwardsFailureMechanism = assessmentSection.MacroStabilityOutwards; + CollectionAssert.IsEmpty(macroStabilityOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(macroStabilityOutwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, macroStabilityOutwardsFailureMechanism); + CollectionAssert.Contains(observables, macroStabilityOutwardsFailureMechanism.SectionResults); + + MicrostabilityFailureMechanism microstabilityFailureMechanism = assessmentSection.Microstability; + CollectionAssert.IsEmpty(microstabilityFailureMechanism.Sections); + CollectionAssert.IsEmpty(microstabilityFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, microstabilityFailureMechanism); + CollectionAssert.Contains(observables, microstabilityFailureMechanism.SectionResults); + + WaterPressureAsphaltCoverFailureMechanism waterPressureAsphaltCoverFailureMechanism = assessmentSection.WaterPressureAsphaltCover; + CollectionAssert.IsEmpty(waterPressureAsphaltCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(waterPressureAsphaltCoverFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, waterPressureAsphaltCoverFailureMechanism); + CollectionAssert.Contains(observables, waterPressureAsphaltCoverFailureMechanism.SectionResults); + + GrassCoverSlipOffOutwardsFailureMechanism grassCoverSlipOffOutwardsFailureMechanism = assessmentSection.GrassCoverSlipOffOutwards; + CollectionAssert.IsEmpty(grassCoverSlipOffOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverSlipOffOutwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, grassCoverSlipOffOutwardsFailureMechanism); + CollectionAssert.Contains(observables, grassCoverSlipOffOutwardsFailureMechanism.SectionResults); + + GrassCoverSlipOffInwardsFailureMechanism grassCoverSlipOffInwardsFailureMechanism = assessmentSection.GrassCoverSlipOffInwards; + CollectionAssert.IsEmpty(grassCoverSlipOffInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverSlipOffInwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, grassCoverSlipOffInwardsFailureMechanism); + CollectionAssert.Contains(observables, grassCoverSlipOffInwardsFailureMechanism.SectionResults); + + StrengthStabilityLengthwiseConstructionFailureMechanism stabilityLengthwiseConstructionFailureMechanism = assessmentSection.StrengthStabilityLengthwiseConstruction; + CollectionAssert.IsEmpty(stabilityLengthwiseConstructionFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityLengthwiseConstructionFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, stabilityLengthwiseConstructionFailureMechanism); + CollectionAssert.Contains(observables, stabilityLengthwiseConstructionFailureMechanism.SectionResults); + + PipingStructureFailureMechanism pipingStructureFailureMechanism = assessmentSection.PipingStructure; + CollectionAssert.IsEmpty(pipingStructureFailureMechanism.Sections); + CollectionAssert.IsEmpty(pipingStructureFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, pipingStructureFailureMechanism); + CollectionAssert.Contains(observables, pipingStructureFailureMechanism.SectionResults); + + TechnicalInnovationFailureMechanism technicalInnovationFailureMechanism = assessmentSection.TechnicalInnovation; + CollectionAssert.IsEmpty(technicalInnovationFailureMechanism.Sections); + CollectionAssert.IsEmpty(technicalInnovationFailureMechanism.SectionResults); + CollectionAssert.Contains(observables, technicalInnovationFailureMechanism); + CollectionAssert.Contains(observables, technicalInnovationFailureMechanism.SectionResults); + + CollectionAssert.AreEqual(referenceLine.Points, assessmentSection.ReferenceLine.Points); + + mocks.VerifyAll(); + } + + [Test] + public void DoPostReplacementUpdates_NoReplaceCalled_DoNothing() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var viewCommands = mocks.StrictMock(); + mocks.ReplayAll(); + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + + // Call + handler.DoPostReplacementUpdates(); + + // Assert + mocks.VerifyAll(); // Expect not calls in 'viewCommands' + } + + [Test] + public void DoPostReplacementUpdates_AfterReplacingReferenceLine_CloseViewsForRemovedData() + { + // Setup + const int expectedNumberOfRemovedInstances = 195; + + var mocks = new MockRepository(); + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(Arg.Is.NotNull)) + .Repeat.Times(expectedNumberOfRemovedInstances); + mocks.ReplayAll(); + + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + handler.Replace(assessmentSection.ReferenceLine, new ReferenceLine()); + + // Call + handler.DoPostReplacementUpdates(); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void DoPostReplacementUpdates_CalledSecondTimeAfterReplaceAndUpdateCycle_DoNothing() + { + // Setup + const int expectedNumberOfRemovedInstances = 195; + + var mocks = new MockRepository(); + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(Arg.Is.NotNull)) + .Repeat.Times(expectedNumberOfRemovedInstances); + mocks.ReplayAll(); + + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); + handler.Replace(assessmentSection.ReferenceLine, new ReferenceLine()); + handler.DoPostReplacementUpdates(); + + // Call + handler.DoPostReplacementUpdates(); // Expected number should be identical to that of DoPostReplacementUpdates_AfterReplacingReferenceLine_CloseViewsForRemovedData + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r45ccc719b2acf50fa50cf7f790ebb7dceb41e28c -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 45ccc719b2acf50fa50cf7f790ebb7dceb41e28c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -65,7 +65,7 @@ - + Index: Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs =================================================================== diff -u -r0e9dc614457e6333c827a9af9395c26458350e1f -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs (.../ReferenceLineImporterIntegrationTest.cs) (revision 0e9dc614457e6333c827a9af9395c26458350e1f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Test/ReferenceLineImporterIntegrationTest.cs (.../ReferenceLineImporterIntegrationTest.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -55,7 +55,7 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); assessmentSection.ReferenceLine.SetGeometry(originalReferenceLineGeometry); - var handler = new ReferenceLineReplacementHandler(assessmentSection, viewCommands); + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp"); var importer = new ReferenceLineImporter(assessmentSection.ReferenceLine, handler, path); @@ -111,7 +111,7 @@ ReferenceLine originalReferenceLine = assessmentSection.ReferenceLine; Point2D[] originalReferenceLineGeometry = originalReferenceLine.Points.ToArray(); - var handler = new ReferenceLineReplacementHandler(assessmentSection, viewCommands); + var handler = new ReferenceLineUpdateHandler(assessmentSection, viewCommands); string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp")); Index: Ringtoets/Integration/test/Ringtoets.Integration.TestUtil/DataImportHelper.cs =================================================================== diff -u -r953e0d229cccbaea58fd9e9ef582504b9fa0cf7c -re949ab20d487bf97ab1cedf2b360fdb1f948419f --- Ringtoets/Integration/test/Ringtoets.Integration.TestUtil/DataImportHelper.cs (.../DataImportHelper.cs) (revision 953e0d229cccbaea58fd9e9ef582504b9fa0cf7c) +++ Ringtoets/Integration/test/Ringtoets.Integration.TestUtil/DataImportHelper.cs (.../DataImportHelper.cs) (revision e949ab20d487bf97ab1cedf2b360fdb1f948419f) @@ -74,7 +74,7 @@ var viewCommands = mocks.Stub(); mocks.ReplayAll(); var activity = new FileImportActivity(new ReferenceLineImporter(assessmentSection.ReferenceLine, - new ReferenceLineReplacementHandler(assessmentSection, viewCommands), + new ReferenceLineUpdateHandler(assessmentSection, viewCommands), filePath), "ReferenceLineImporter"); activity.Run();