Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -553,7 +553,7 @@ Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil"), new StochasticSoilModelReplaceDataStrategy(), - new StochasticSoilModelChangeHandler()); + new StochasticSoilModelChangeHandler(pipingFailureMechanism)); soilProfilesImporter.Import(); } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/IStochasticSoilModelChangeHandler.cs =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/IStochasticSoilModelChangeHandler.cs (.../IStochasticSoilModelChangeHandler.cs) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/IStochasticSoilModelChangeHandler.cs (.../IStochasticSoilModelChangeHandler.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -21,10 +21,25 @@ namespace Ringtoets.Piping.IO.Importer { + /// + /// Interface for verifying and handling changes as an effect of a change to the stochastic + /// soil model collection. + /// public interface IStochasticSoilModelChangeHandler { + /// + /// Verifies whether the change to the stochastic soil model collections has side-effects; + /// and therefore a confirmation is required. + /// + /// true if confirmation is required, false otherwise. bool RequireConfirmation(); + /// + /// Inquires for a confirmation. + /// + /// true if confirmation is given; false otherwise. + /// Should only be called when returns true. + /// bool InquireConfirmation(); } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelChangeHandler.cs =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelChangeHandler.cs (.../StochasticSoilModelChangeHandler.cs) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelChangeHandler.cs (.../StochasticSoilModelChangeHandler.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -19,20 +19,54 @@ // 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 Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Importer; +using Ringtoets.Piping.Plugin.Properties; +using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; namespace Ringtoets.Piping.Plugin.FileImporter { + /// + /// 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 : IStochasticSoilModelChangeHandler { + private readonly PipingFailureMechanism failureMechanism; + + public StochasticSoilModelChangeHandler(PipingFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + this.failureMechanism = failureMechanism; + } + public bool RequireConfirmation() { - return false; + IEnumerable calculations = failureMechanism.Calculations.Cast(); + + return calculations.Any(HasOutput); } + private static bool HasOutput(PipingCalculationScenario calculation) + { + return calculation.HasOutput; + } + public bool InquireConfirmation() { - throw new System.NotImplementedException(); + DialogResult result = MessageBox.Show( + Resources.StochasticSoilModelChangeHandler_When_updating_StochasticSoilModel_definitions_assigned_to_calculations_output_will_be_cleared_confirm, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + + return result == DialogResult.OK; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r0ab02f0514e081770486d6a9b1b4fbcd9c92d642 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 0ab02f0514e081770486d6a9b1b4fbcd9c92d642) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -119,7 +119,7 @@ CreateFileImporter = (context, filePath) => new StochasticSoilModelImporter(context.WrappedData, filePath, new StochasticSoilModelReplaceDataStrategy(), - new StochasticSoilModelChangeHandler()) + new StochasticSoilModelChangeHandler(context.FailureMechanism)) }; } @@ -573,7 +573,7 @@ var importer = new StochasticSoilModelImporter(soilModelCollection, sourceFilePath, new StochasticSoilModelUpdateDataStrategy(failureMechanism), - new StochasticSoilModelChangeHandler()); + new StochasticSoilModelChangeHandler(failureMechanism)); var activity = new FileImportActivity(importer, PipingPluginResources.PipingPlugin_RunUpdateStochasticSoilModel_Update_StochasticSoilModels); ActivityProgressDialogRunner.Run(Gui.MainWindow, activity); Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -383,6 +383,16 @@ } /// + /// Looks up a localized string similar to Wanneer ondergrondschematisaties wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze ondergrondschematisaties worden verwijderd. Weet u zeker dat u wilt doorgaan?. + /// + public static string StochasticSoilModelChangeHandler_When_updating_StochasticSoilModel_definitions_assigned_to_calculations_output_will_be_cleared_confirm { + get { + return ResourceManager.GetString("StochasticSoilModelChangeHandler_When_updating_StochasticSoilModel_definitions_as" + + "signed_to_calculations_output_will_be_cleared_confirm", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het stochastische ondergrondmodel '{0}' bestaat al in het toetsspoor.. /// public static string StochasticSoilModelImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists { Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -220,4 +220,7 @@ Het bijwerken van de stochastische ondrgrondmodellen is mislukt. + + Wanneer ondergrondschematisaties wijzigen als gevolg van het bijwerken, zullen de resultaten van berekeningen die deze ondergrondschematisaties worden verwijderd. Weet u zeker dat u wilt doorgaan? + \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs =================================================================== diff -u -r34f1b5a53b9c554d1a0a35365da4f8d258117304 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision 34f1b5a53b9c554d1a0a35365da4f8d258117304) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -302,7 +302,7 @@ private static string GetRandomName(Random random) { - return string.Join("", Enumerable.Repeat('x', random.Next(0, 40))); + return new string('x', random.Next(0, 40)); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs =================================================================== diff -u -r34f1b5a53b9c554d1a0a35365da4f8d258117304 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 34f1b5a53b9c554d1a0a35365da4f8d258117304) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -247,7 +247,7 @@ private static string GetRandomName(Random random) { - return string.Join("", Enumerable.Repeat('x', random.Next(0, 40))); + return new string('x', random.Next(0, 40)); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelChangeHandlerTest.cs =================================================================== diff -u -r4dac504d83de712731e5f7ae1116b8e2d27caf06 -r76a7de2e77e45645d0e7e485e03333baf9cc3b0d --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelChangeHandlerTest.cs (.../StochasticSoilModelChangeHandlerTest.cs) (revision 4dac504d83de712731e5f7ae1116b8e2d27caf06) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelChangeHandlerTest.cs (.../StochasticSoilModelChangeHandlerTest.cs) (revision 76a7de2e77e45645d0e7e485e03333baf9cc3b0d) @@ -20,48 +20,136 @@ // All rights reserved. using System; +using NUnit.Extensions.Forms; using NUnit.Framework; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.TestUtil; using Ringtoets.Piping.IO.Importer; +using Ringtoets.Piping.KernelWrapper.TestUtil; using Ringtoets.Piping.Plugin.FileImporter; namespace Ringtoets.Piping.Plugin.Test.FileImporter { [TestFixture] - public class StochasticSoilModelChangeHandlerTest + public class StochasticSoilModelChangeHandlerTest : NUnitFormTest { [Test] - public void DefaultConstructor_ImplementedExpectedInterface() + public void Constructor_WithoutFailureMechanism_ThrowsArgumentNullException() { // Call - var handler = new StochasticSoilModelChangeHandler(); + TestDelegate test = () => new StochasticSoilModelChangeHandler(null); // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void Constructor_WithFailureMechanism_ImplementsExpectedInterface() + { + // Call + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism()); + + // Assert Assert.IsInstanceOf(handler); } [Test] - public void RequireConfirmation_Always_ReturnFalse() + public void RequireConfirmation_FailureMechanismWithCalculationWithoutOutput_ReturnFalse() { // Setup - var handler = new StochasticSoilModelChangeHandler(); + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput())); + var handler = new StochasticSoilModelChangeHandler(failureMechanism); + // Call bool requireConfirmation = handler.RequireConfirmation(); // Assert Assert.IsFalse(requireConfirmation); } + [Test] - public void InquireConfirmation_Always_ThrowsNotImplementedException() + public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue() { // Setup - var handler = new StochasticSoilModelChangeHandler(); + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }); + var handler = new StochasticSoilModelChangeHandler(failureMechanism); + // Call - TestDelegate testDelegate = () => handler.InquireConfirmation(); + bool requireConfirmation = handler.RequireConfirmation(); // Assert - Assert.Throws(testDelegate); + Assert.IsTrue(requireConfirmation); } + + [Test] + public void InquireConfirmation_Always_ShowsConfirmationDialog() + { + // Setup + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism()); + + string dialogText = string.Empty; + + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + dialogText = tester.Text; + tester.ClickCancel(); + }; + + // Call + handler.InquireConfirmation(); + + // Assert + const string message = "Wanneer ondergrondschematisaties wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze ondergrondschematisaties worden " + + "verwijderd. Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(message, dialogText); + } + + [Test] + public void InquireConfirmation_PressOkInMessageBox_ReturnsTrue() + { + // Setup + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism()); + + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + // Call + var confirmed = handler.InquireConfirmation(); + + // Assert + Assert.IsTrue(confirmed); + } + + [Test] + public void InquireConfirmation_PressCancelInMessageBox_ReturnsFalse() + { + // Setup + var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism()); + + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickCancel(); + }; + + // Call + var confirmed = handler.InquireConfirmation(); + + // Assert + Assert.IsFalse(confirmed); + } } } \ No newline at end of file