Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandler.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandler.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandler.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,80 @@ +// 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.Generic; +using System.Linq; +using Core.Common.Gui; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Plugin.Properties; + +namespace Ringtoets.Piping.Plugin.ChangeHandlers +{ + /// + /// Class which can, if required, inquire the user for a confirmation when a change to the + /// surface line collection requires calculation results to be altered. + /// + public class RingtoetsPipingSurfaceLineChangeHandler : IConfirmDataChangeHandler + { + private readonly IInquiryHelper inquiryHandler; + private readonly PipingFailureMechanism failureMechanism; + + /// + /// Creates a new instance of . + /// + /// Failure mechanism for which to handle changes in stochastic soil models. + /// Object responsible for inquiring required data. + /// Thrown when any input parameter is null. + public RingtoetsPipingSurfaceLineChangeHandler(PipingFailureMechanism failureMechanism, IInquiryHelper inquiryHandler) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + + this.failureMechanism = failureMechanism; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + IEnumerable calculations = failureMechanism.Calculations.Cast(); + + return calculations.Any(HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation( + Resources.RingtoetsPipingSurfaceLineChangeHandler_InquireConfirmation_When_updating_RingtoetsSurfaceLines_definitions_assigned_to_calculations_output_will_be_cleared_confirm); + } + + private static bool HasOutput(PipingCalculation calculation) + { + return calculation.HasOutput; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/StochasticSoilModelChangeHandler.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/StochasticSoilModelChangeHandler.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/StochasticSoilModelChangeHandler.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,79 @@ +// 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.Generic; +using System.Linq; +using Core.Common.Gui; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Plugin.Properties; + +namespace Ringtoets.Piping.Plugin.ChangeHandlers +{ + /// + /// Class which can, if required, inquire the user for a confirmation when a change to the + /// stochastic soil model collection requires calculation results to be altered. + /// + public class StochasticSoilModelChangeHandler : IConfirmDataChangeHandler + { + private readonly PipingFailureMechanism failureMechanism; + private readonly IInquiryHelper inquiryHandler; + + /// + /// Creates new instance of + /// + /// Failure mechanism for which to handle changes in stochastic soil models. + /// Object responsible for inquiring required data. + /// Thrown when any input parameter is null. + public StochasticSoilModelChangeHandler(PipingFailureMechanism failureMechanism, IInquiryHelper inquiryHandler) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + this.failureMechanism = failureMechanism; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + IEnumerable calculations = failureMechanism.Calculations.Cast(); + + return calculations.Any(HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation( + Resources.StochasticSoilModelChangeHandler_When_updating_StochasticSoilModel_definitions_assigned_to_calculations_output_will_be_cleared_confirm); + } + + private static bool HasOutput(PipingCalculationScenario calculation) + { + return calculation.HasOutput; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/UpdateEntryAndExitPointsCalculationGroupChangeHandler.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/UpdateEntryAndExitPointsCalculationGroupChangeHandler.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/ChangeHandlers/UpdateEntryAndExitPointsCalculationGroupChangeHandler.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,72 @@ +// 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.Generic; +using System.Linq; +using Core.Common.Gui; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Plugin.Properties; + +namespace Ringtoets.Piping.Plugin.ChangeHandlers +{ + /// + /// + /// + public class UpdateEntryAndExitPointsCalculationGroupChangeHandler : IConfirmDataChangeHandler + { + private readonly IEnumerable calculations; + private readonly IInquiryHelper inquiryHandler; + + /// + /// Instantiates a . + /// + /// The calculations for which to handle the changes in the entry and exit points. + /// Object responsible for inquiring required data. + /// Thrown when any input parameter is null. + public UpdateEntryAndExitPointsCalculationGroupChangeHandler(IEnumerable calculations, IInquiryHelper inquiryHandler) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + if (inquiryHandler == null) + { + throw new ArgumentNullException(nameof(inquiryHandler)); + } + + this.calculations = calculations; + this.inquiryHandler = inquiryHandler; + } + + public bool RequireConfirmation() + { + return calculations.Any(calc => calc.HasOutput); + } + + public bool InquireConfirmation() + { + return inquiryHandler.InquireContinuation( + Resources.UpdateEntryAndExitPointsCalculationGroupChangeHandler_InquireConfirmation_When_updating_entry_and_exit_points_definitions_assigned_to_calculations_output_will_be_cleared_confirm); + } + } +} Fisheye: Tag 03fae882dff9db344c9380368a85ecdf3ab46f2a refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineChangeHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 03fae882dff9db344c9380368a85ecdf3ab46f2a refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelChangeHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r5cac0be5a13b25f4e34680f9c3da63ec537a4ef3 -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 5cac0be5a13b25f4e34680f9c3da63ec537a4ef3) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -47,6 +47,7 @@ using Ringtoets.Piping.Forms.Views; using Ringtoets.Piping.IO.Exporters; using Ringtoets.Piping.IO.Importers; +using Ringtoets.Piping.Plugin.ChangeHandlers; using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Plugin.Properties; using Ringtoets.Piping.Primitives; @@ -1029,24 +1030,57 @@ parentGroupContext.NotifyObservers(); } - private static StrictContextMenuItem CreateUpdateEntryAndExitPointItem(PipingCalculationGroupContext nodeData) + private StrictContextMenuItem CreateUpdateEntryAndExitPointItem(PipingCalculationGroupContext nodeData) { + IEnumerable calculations = nodeData.WrappedData.GetCalculations().OfType(); + + var isItemEnabled = true; + string toolTipText = Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_Update_all_calculations_with_characteristic_points_ToolTip; + if (!calculations.Any()) + { + isItemEnabled = false; + toolTipText = Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip; + } + else + { + if (calculations.All(calc => calc.InputParameters.SurfaceLine == null)) + { + isItemEnabled = false; + toolTipText = Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_with_surfaceline_Tooltip; + } + } + return new StrictContextMenuItem( Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_Update_all_entry_and_exit_points, - Resources.PipingPlugin_CreateUpdateEntryAndExitPointItem_Update_all_calculations_with_characteristic_points_ToolTip, + toolTipText, RingtoetsCommonFormsResources.UpdateItemIcon, - (sender, args) => UpdateAllEntryAndExitPointsOfAllCalculations(nodeData)); + (sender, args) => UpdateAllEntryAndExitPointsOfAllCalculations(nodeData)) + { + Enabled = isItemEnabled + }; } - private static void UpdateAllEntryAndExitPointsOfAllCalculations(PipingCalculationGroupContext nodeData) + private void UpdateAllEntryAndExitPointsOfAllCalculations(PipingCalculationGroupContext nodeData) { - IEnumerable calculations = nodeData.WrappedData.GetCalculations().OfType(); - foreach (PipingCalculationScenario calculation in calculations) + PipingCalculationScenario[] calculations = nodeData.WrappedData.GetCalculations().OfType().ToArray(); + + if (VerifyEntryAndExitPointUpdates(calculations)) { - UpdateSurfaceLineDependentData(calculation); + foreach (PipingCalculationScenario calculation in calculations) + { + UpdateSurfaceLineDependentData(calculation); + } } } + private bool VerifyEntryAndExitPointUpdates(IEnumerable calculations) + { + var changeHandler = new UpdateEntryAndExitPointsCalculationGroupChangeHandler(calculations, + new DialogBasedInquiryHelper(Gui.MainWindow)); + + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } + #endregion #region Ringtoets piping surface line importer Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r9ad3a25b98327fbb360663497753e166e095fb4b -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 9ad3a25b98327fbb360663497753e166e095fb4b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -82,6 +82,25 @@ } /// + /// Looks up a localized string similar to Er zijn geen berekeningen om bij te werken.. + /// + public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip { + get { + return ResourceManager.GetString("PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_to_update_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er zijn geen berekeningen met een profielschematisatie.. + /// + public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_with_surfaceline_Tooltip { + get { + return ResourceManager.GetString("PipingPlugin_CreateUpdateEntryAndExitPointItem_No_calculations_with_surfaceline_T" + + "ooltip", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Alle berekeningen bijwerken met de karakteristieke punten.. /// public static string PipingPlugin_CreateUpdateEntryAndExitPointItem_Update_all_calculations_with_characteristic_points_ToolTip { @@ -501,5 +520,18 @@ "asticSoilModel_failed", resourceCulture); } } + + /// + /// Looks up a localized string similar to Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + public static string UpdateEntryAndExitPointsCalculationGroupChangeHandler_InquireConfirmation_When_updating_entry_and_exit_points_definitions_assigned_to_calculations_output_will_be_cleared_confirm { + get { + return ResourceManager.GetString("UpdateEntryAndExitPointsCalculationGroupChangeHandler_InquireConfirmation_When_up" + + "dating_entry_and_exit_points_definitions_assigned_to_calculations_output_will_be" + + "_cleared_confirm", resourceCulture); + } + } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -r9ad3a25b98327fbb360663497753e166e095fb4b -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 9ad3a25b98327fbb360663497753e166e095fb4b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -253,4 +253,15 @@ &Bijwerken alle intrede- en uittredepunten + + Er zijn geen berekeningen om bij te werken. + + + Er zijn geen berekeningen met een profielschematisatie. + + + Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden verwijderd. + +Weet u zeker dat u wilt doorgaan? + \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj =================================================================== diff -u -r583456a0f5395189a54a8cedf4e4a7b40945d990 -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 583456a0f5395189a54a8cedf4e4a7b40945d990) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -59,10 +59,11 @@ Properties\GlobalAssembly.cs - + + - + Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandlerTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/RingtoetsPipingSurfaceLineChangeHandlerTest.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,150 @@ +// 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 Core.Common.Gui; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Plugin.ChangeHandlers; + +namespace Ringtoets.Piping.Plugin.Test.ChangeHandlers +{ + [TestFixture] + public class RingtoetsPipingSurfaceLineChangeHandlerTest + { + [Test] + public void Constructor_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new RingtoetsPipingSurfaceLineChangeHandler(null, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new RingtoetsPipingSurfaceLineChangeHandler(new PipingFailureMechanism(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + var handler = new RingtoetsPipingSurfaceLineChangeHandler(new PipingFailureMechanism(), inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput())); + + var handler = new RingtoetsPipingSurfaceLineChangeHandler(failureMechanism, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }); + + var handler = new RingtoetsPipingSurfaceLineChangeHandler(failureMechanism, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(bool expectedResult) + { + // Setup + string message = "Wanneer profielschematisaties wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + mockRepository.ReplayAll(); + + var handler = new RingtoetsPipingSurfaceLineChangeHandler(new PipingFailureMechanism(), inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/StochasticSoilModelChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/StochasticSoilModelChangeHandlerTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/StochasticSoilModelChangeHandlerTest.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,151 @@ +// 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 Core.Common.Gui; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Plugin.ChangeHandlers; + +namespace Ringtoets.Piping.Plugin.Test.ChangeHandlers +{ + [TestFixture] + public class StochasticSoilModelChangeHandlerTest : NUnitFormTest + { + [Test] + public void Constructor_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new StochasticSoilModelChangeHandler(null, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput())); + + var handler = new StochasticSoilModelChangeHandler(failureMechanism, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }); + + var handler = new StochasticSoilModelChangeHandler(failureMechanism, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(bool expectedResult) + { + // Setup + string message = "Wanneer ondergrondschematisaties wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze ondergrondschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + mockRepository.ReplayAll(); + + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateCharacteristicPointsCalculationGroupChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateCharacteristicPointsCalculationGroupChangeHandlerTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ChangeHandlers/UpdateCharacteristicPointsCalculationGroupChangeHandlerTest.cs (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -0,0 +1,158 @@ +// 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.Generic; +using System.Linq; +using System.Text; +using Core.Common.Gui; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Plugin.ChangeHandlers; + +namespace Ringtoets.Piping.Plugin.Test.ChangeHandlers +{ + [TestFixture] + public class UpdateCharacteristicPointsCalculationGroupChangeHandlerTest + { + [Test] + public void Constructor_WithoutCalculations_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + TestDelegate test = () => new UpdateEntryAndExitPointsCalculationGroupChangeHandler(null, inquiryHandler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("calculations", paramName); + mockRepository.VerifyAll(); + } + + [Test] + public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new UpdateEntryAndExitPointsCalculationGroupChangeHandler(Enumerable.Empty(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("inquiryHandler", paramName); + } + + [Test] + public void Constructor_WithParameters_ImplementsExpectedInterface() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + // Call + var handler = new UpdateEntryAndExitPointsCalculationGroupChangeHandler(Enumerable.Empty(), inquiryHandler); + + // Assert + Assert.IsInstanceOf(handler); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_WithCalculationWithoutOutput_ReturnFalse() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + IEnumerable calculations = new List + { + new PipingCalculationScenario(new GeneralPipingInput()) + }; + + var handler = new UpdateEntryAndExitPointsCalculationGroupChangeHandler(calculations, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsFalse(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + public void RequireConfirmation_CalculationsWithoutAndWithOutput_ReturnTrue() + { + // Setup + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + IEnumerable calculations = new List + { + new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }, + new PipingCalculationScenario(new GeneralPipingInput()) + }; + + var handler = new UpdateEntryAndExitPointsCalculationGroupChangeHandler(calculations, inquiryHandler); + + // Call + bool requireConfirmation = handler.RequireConfirmation(); + + // Assert + Assert.IsTrue(requireConfirmation); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(bool expectedResult) + { + // Setup + string message = "Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + var mockRepository = new MockRepository(); + var inquiryHandler = mockRepository.StrictMock(); + inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult); + mockRepository.ReplayAll(); + + var handler = new UpdateEntryAndExitPointsCalculationGroupChangeHandler(Enumerable.Empty(), inquiryHandler); + + // Call + bool result = handler.InquireConfirmation(); + + // Assert + Assert.AreEqual(expectedResult, result); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag 03fae882dff9db344c9380368a85ecdf3ab46f2a refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineChangeHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 03fae882dff9db344c9380368a85ecdf3ab46f2a refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelChangeHandlerTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -r26da131fa5dbcf95f9a16de6f81eb4acc8d1be14 -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 26da131fa5dbcf95f9a16de6f81eb4acc8d1be14) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -72,11 +72,12 @@ Properties\GlobalAssembly.cs + - + - + Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r5cac0be5a13b25f4e34680f9c3da63ec537a4ef3 -r03fae882dff9db344c9380368a85ecdf3ab46f2a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision 5cac0be5a13b25f4e34680f9c3da63ec537a4ef3) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision 03fae882dff9db344c9380368a85ecdf3ab46f2a) @@ -269,8 +269,9 @@ CoreCommonGuiResources.RenameIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup, "&Bijwerken alle intrede- en uittredepunten", - "Alle berekeningen bijwerken met de karakteristieke punten.", - RingtoetsCommonFormsResources.UpdateItemIcon); + "Er zijn geen berekeningen met een profielschematisatie.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexNestedGroup, "Alles &valideren", "Valideer alle berekeningen binnen deze berekeningsmap.", @@ -390,8 +391,9 @@ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken alle intrede- en uittredepunten", - "Alle berekeningen bijwerken met de karakteristieke punten.", - RingtoetsCommonFormsResources.UpdateItemIcon); + "Er zijn geen berekeningen met een profielschematisatie.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, "Alles &valideren", "Valideer alle berekeningen binnen deze berekeningsmap.", @@ -658,6 +660,125 @@ } [Test] + public void ContextMenuStrip_NoCalculations_ContextMenuItemUpdateEntryAndExitPointDisabled() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var pipingFailureMechanism = new TestPipingFailureMechanism(); + + var assessmentSection = mocks.Stub(); + var group = new CalculationGroup(); + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSection); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, + contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, + "&Bijwerken alle intrede- en uittredepunten", + "Er zijn geen berekeningen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationsWithoutSurfaceLine_ContextMenuItemUpdateEntryAndExitPointDisabled() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var pipingFailureMechanism = new TestPipingFailureMechanism(); + var assessmentSection = mocks.Stub(); + var group = new CalculationGroup + { + Children = + { + new PipingCalculationScenario(new GeneralPipingInput()) + } + }; + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSection); + + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, + contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, + "&Bijwerken alle intrede- en uittredepunten", + "Er zijn geen berekeningen met een profielschematisatie.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationsWithSurfaceLine_ContextMenuItemUpdateEntryAndExitPointEnabled() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var pipingFailureMechanism = new TestPipingFailureMechanism(); + var assessmentSection = mocks.Stub(); + var group = new CalculationGroup + { + Children = + { + PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput() + } + }; + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSection); + + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, + contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, + "&Bijwerken alle intrede- en uittredepunten", + "Alle berekeningen bijwerken met de karakteristieke punten.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] public void ContextMenuStrip_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers() { // Setup @@ -1365,7 +1486,7 @@ } [Test] - public void GivenCalculationInNestedGroupWithOutputs_WhenEntryAndExitPointsUpdatedAndUpdateEntryAndExitPointsClicked_ThenCalculationsUpdatedAndObserversNotified() + public void GivenCalculationInNestedGroupWithOutputs_WhenEntryAndExitPointsUpdatedAndUpdateEntryAndExitPointsClickedAndContinued_ThenCalculationsUpdatedAndObserversNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1443,12 +1564,23 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + helper.ClickOk(); + textBoxMessage = helper.Text; + }; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When @@ -1479,12 +1611,17 @@ Assert.AreSame(surfaceLine, inputParameters2.SurfaceLine); Assert.AreEqual(new RoundedDouble(2, 2), inputParameters2.EntryPointL); Assert.AreEqual(new RoundedDouble(3, 3), inputParameters2.ExitPointL); + + string expectedMessage = "Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); } } } [Test] - public void GivenCalculationInNestedGroupWithoutOutputs_WhenEntryAndExitPointsUpdatedAndUpdateEntryAndExitPointsClicked_ThenCalculationsUpdatedAndObserversNotified() + public void GivenCalculationInNestedGroupWithoutOutputs_WhenEntryAndExitPointsUpdatedAndUpdateEntryAndExitPointsClickedAndContinued_ThenCalculationsUpdatedAndObserversNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1556,8 +1693,11 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -1594,7 +1734,7 @@ } [Test] - public void GivenCalculationInNestedGroupWithOutputs_WhenUpdatedEntryAndExitPointsHasNoChangeAndUpdateEntryAndExitPointsClicked_ThenCalculationsUpdatedAndObserversNotified() + public void GivenCalculationInNestedGroupWithOutputs_WhenUpdatedEntryAndExitPointsHasNoChangeAndUpdateEntryAndExitPointsClickedAndContinued_ThenCalculationsUpdatedAndObserversNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1667,12 +1807,23 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + helper.ClickOk(); + textBoxMessage = helper.Text; + }; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When @@ -1703,10 +1854,258 @@ Assert.AreSame(surfaceLine, inputParameters2.SurfaceLine); Assert.AreEqual(new RoundedDouble(2, 2), inputParameters2.EntryPointL); Assert.AreEqual(new RoundedDouble(3, 3), inputParameters2.ExitPointL); + + string expectedMessage = "Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); } } } + [Test] + public void GivenCalculationInNestedGroupWithOutputs_WhenUpdatedEntryAndExitPointsHasChangeAndUpdateEntryAndExitPointsClickedAndDiscontinued_ThenCalculationsNotUpdated() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var calculation1Observer = mocks.StrictMock(); + var calculation1InputObserver = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + var calculation2InputObserver = mocks.StrictMock(); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + + var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + EntryPointL = (RoundedDouble) 0, + ExitPointL = (RoundedDouble) 1 + }, + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + EntryPointL = (RoundedDouble) 0, + ExitPointL = (RoundedDouble) 1 + }, + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var pipingFailureMechanism = new PipingFailureMechanism(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( + pipingFailureMechanism, mocks); + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionStub); + var parentNodeData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionStub); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + helper.ClickCancel(); + textBoxMessage = helper.Text; + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) + { + // When + surfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(1, 0, 2), + new Point3D(2, 0, 3), + new Point3D(3, 0, 0), + new Point3D(4, 0, 2), + new Point3D(5, 0, 3) + }); + surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); + surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + + contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation1.HasOutput); + Assert.IsTrue(calculation2.HasOutput); + + PipingInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(surfaceLine, inputParameters1.SurfaceLine); + Assert.AreEqual(new RoundedDouble(2, 0), inputParameters1.EntryPointL); + Assert.AreEqual(new RoundedDouble(3, 1), inputParameters1.ExitPointL); + + PipingInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(surfaceLine, inputParameters2.SurfaceLine); + Assert.AreEqual(new RoundedDouble(2, 0), inputParameters2.EntryPointL); + Assert.AreEqual(new RoundedDouble(3, 1), inputParameters2.ExitPointL); + + string expectedMessage = "Wanneer de intrede- en uittrede punten wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze profielschematisaties gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + } + } + } + + [Test] + public void GivenCalculationInNestedGroupWithoutOutputs_WhenUpdatedEntryAndExitPoints_ThenNoInquiryAndCalculationsUpdatedAndObserversNotified() + { + // Setup + using (var treeViewControl = new TreeViewControl()) + { + var calculation1Observer = mocks.StrictMock(); + var calculation1InputObserver = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + var calculation2InputObserver = mocks.StrictMock(); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + + var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + EntryPointL = (RoundedDouble) 2, + ExitPointL = (RoundedDouble) 3 + } + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + EntryPointL = (RoundedDouble) 2, + ExitPointL = (RoundedDouble) 3 + }, + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var pipingFailureMechanism = new PipingFailureMechanism(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( + pipingFailureMechanism, mocks); + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionStub); + var parentNodeData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionStub); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) + { + // When + surfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(1, 0, 2), + new Point3D(2, 0, 3), + new Point3D(3, 0, 0), + new Point3D(4, 0, 2), + new Point3D(5, 0, 3) + }); + surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); + surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + + contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation1.HasOutput); + Assert.IsFalse(calculation2.HasOutput); + + PipingInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(surfaceLine, inputParameters1.SurfaceLine); + Assert.AreEqual(new RoundedDouble(2, 2), inputParameters1.EntryPointL); + Assert.AreEqual(new RoundedDouble(3, 3), inputParameters1.ExitPointL); + + PipingInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(surfaceLine, inputParameters2.SurfaceLine); + Assert.AreEqual(new RoundedDouble(2, 2), inputParameters2.EntryPointL); + Assert.AreEqual(new RoundedDouble(3, 3), inputParameters2.ExitPointL); + } + } + } + public override void TearDown() { plugin.Dispose();