Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -r92acb4483676af5adad598c2ea8ca46f9b8379c1 -rb9588439685292e10bcf3a4fcebfc187fd7bd03e --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision b9588439685292e10bcf3a4fcebfc187fd7bd03e) @@ -202,7 +202,10 @@ Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsCommonFormsResources.StructuresIcon, FileFilterGenerator = CreateStabilityPointStructureFileFilter(), - IsEnabled = context => context.AssessmentSection.ReferenceLine != null + IsEnabled = context => context.AssessmentSection.ReferenceLine != null, + VerifyUpdates = context => VerifyStructuresShouldUpdate( + context.FailureMechanism, + RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_importing_Calculation_with_Structure_data_output_will_be_cleared_confirm) }; yield return RingtoetsImportInfoFactory.CreateCalculationConfigurationImportInfo( @@ -242,7 +245,10 @@ Image = RingtoetsCommonFormsResources.StructuresIcon, FileFilterGenerator = CreateStabilityPointStructureFileFilter(), IsEnabled = context => context.WrappedData.SourcePath != null, - CurrentPath = context => context.WrappedData.SourcePath + CurrentPath = context => context.WrappedData.SourcePath, + VerifyUpdates = context => VerifyStructuresShouldUpdate( + context.FailureMechanism, + RingtoetsCommonIOResources.VerifyStructuresShouldUpdate_When_updating_Calculation_with_Structure_data_output_will_be_cleared_confirm) }; } @@ -877,6 +883,15 @@ RingtoetsCommonIOResources.Shape_file_filter_Description); } + private bool VerifyStructuresShouldUpdate(IFailureMechanism failureMechanism, string query) + { + var changeHandler = new FailureMechanismCalculationChangeHandler(failureMechanism, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); + + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } + #endregion } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ImportInfos/StabilityPointStructuresContextImportInfoTest.cs =================================================================== diff -u -rc4e2a1db42a818567d116298b5c163b56b69ce0e -rb9588439685292e10bcf3a4fcebfc187fd7bd03e --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ImportInfos/StabilityPointStructuresContextImportInfoTest.cs (.../StabilityPointStructuresContextImportInfoTest.cs) (revision c4e2a1db42a818567d116298b5c163b56b69ce0e) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/ImportInfos/StabilityPointStructuresContextImportInfoTest.cs (.../StabilityPointStructuresContextImportInfoTest.cs) (revision b9588439685292e10bcf3a4fcebfc187fd7bd03e) @@ -19,15 +19,22 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Drawing; using System.Linq; using Core.Common.Base.IO; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using Core.Common.Utils; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; using Ringtoets.StabilityPointStructures.IO; @@ -36,7 +43,7 @@ namespace Ringtoets.StabilityPointStructures.Plugin.Test.ImportInfos { [TestFixture] - public class StabilityPointStructuresContextImportInfoTest + public class StabilityPointStructuresContextImportInfoTest :NUnitFormTest { [Test] public void CreateFileImporter_Always_ReturnFileImporter() @@ -186,6 +193,93 @@ mocks.VerifyAll(); } + [Test] + public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); + + var structures = new StructureCollection(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + + using (var plugin = new StabilityPointStructuresPlugin()) + { + plugin.Gui = gui; + + ImportInfo importInfo = GetImportInfo(plugin); + + // Call + bool updatesVerified = importInfo.VerifyUpdates(context); + + // Assert + Assert.IsTrue(updatesVerified); + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation + { + Output = new TestStructuresOutput() + }); + + var structures = new StructureCollection(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + + if (isActionConfirmed) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; + + using (var plugin = new StabilityPointStructuresPlugin()) + { + plugin.Gui = gui; + ImportInfo importInfo = GetImportInfo(plugin); + + // Call + bool updatesVerified = importInfo.VerifyUpdates(context); + + // Assert + string expectedInquiryMessage = "Als u kunstwerken importeert, dan worden alle rekenresultaten van dit toetsspoor verwijderd." + + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedInquiryMessage, textBoxMessage); + Assert.AreEqual(isActionConfirmed, updatesVerified); + mocks.VerifyAll(); + } + } + private static ImportInfo GetImportInfo(StabilityPointStructuresPlugin plugin) { return plugin.GetImportInfos().First(ii => ii.DataType == typeof(StabilityPointStructuresContext)); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs =================================================================== diff -u -r92acb4483676af5adad598c2ea8ca46f9b8379c1 -rb9588439685292e10bcf3a4fcebfc187fd7bd03e --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs (.../StabilityPointStructuresContextUpdateInfoTest.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs (.../StabilityPointStructuresContextUpdateInfoTest.cs) (revision b9588439685292e10bcf3a4fcebfc187fd7bd03e) @@ -19,16 +19,21 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Drawing; using System.Linq; using Core.Common.Base.IO; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; using Ringtoets.StabilityPointStructures.IO; @@ -37,158 +42,233 @@ namespace Ringtoets.StabilityPointStructures.Plugin.Test.UpdateInfos { [TestFixture] - public class StabilityPointStructuresContextUpdateInfoTest + public class StabilityPointStructuresContextUpdateInfoTest : NUnitFormTest { - [TestFixture] - public class ClosingStructuresContextUpdateInfoTest : NUnitFormTest + private UpdateInfo updateInfo; + private StabilityPointStructuresPlugin plugin; + + [SetUp] + public void SetUp() { - private UpdateInfo updateInfo; - private StabilityPointStructuresPlugin plugin; + plugin = new StabilityPointStructuresPlugin(); + updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(StabilityPointStructuresContext)); + } - [SetUp] - public void SetUp() - { - plugin = new StabilityPointStructuresPlugin(); - updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(StabilityPointStructuresContext)); - } + [TearDown] + public override void TearDown() + { + plugin.Dispose(); + } - [TearDown] - public override void TearDown() - { - plugin.Dispose(); - } + [Test] + public void Name_Always_ReturnExpectedName() + { + // Call + string name = updateInfo.Name; - [Test] - public void Name_Always_ReturnExpectedName() - { - // Call - string name = updateInfo.Name; + // Assert + Assert.AreEqual("Kunstwerken", name); + } - // Assert - Assert.AreEqual("Kunstwerken", name); - } + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Call + string category = updateInfo.Category; - [Test] - public void Category_Always_ReturnExpectedCategory() - { - // Call - string category = updateInfo.Category; + // Assert + Assert.AreEqual("Algemeen", category); + } - // Assert - Assert.AreEqual("Algemeen", category); - } + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Call + Image image = updateInfo.Image; - [Test] - public void Image_Always_ReturnExpectedIcon() - { - // Call - Image image = updateInfo.Image; + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + } - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); - } + [Test] + public void IsEnabled_SourcePathNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - [Test] - public void IsEnabled_SourcePathNull_ReturnFalse() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var structures = new StructureCollection(); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var structures = new StructureCollection(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); - var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + // Call + bool isEnabled = updateInfo.IsEnabled(context); - // Call - bool isEnabled = updateInfo.IsEnabled(context); + // Assert + Assert.IsFalse(isEnabled); + mocks.VerifyAll(); + } - // Assert - Assert.IsFalse(isEnabled); - mocks.VerifyAll(); - } + [Test] + public void IsEnabled_SourcePathSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - [Test] - public void IsEnabled_SourcePathSet_ReturnTrue() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.StabilityPointStructures.AddRange(Enumerable.Empty(), "some path"); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - failureMechanism.StabilityPointStructures.AddRange(Enumerable.Empty(), "some path"); + var context = new StabilityPointStructuresContext(failureMechanism.StabilityPointStructures, + failureMechanism, + assessmentSection); - var context = new StabilityPointStructuresContext(failureMechanism.StabilityPointStructures, - failureMechanism, - assessmentSection); + // Call + bool isEnabled = updateInfo.IsEnabled(context); - // Call - bool isEnabled = updateInfo.IsEnabled(context); + // Assert + Assert.IsTrue(isEnabled); + mocks.VerifyAll(); + } - // Assert - Assert.IsTrue(isEnabled); - mocks.VerifyAll(); - } + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Call + string fileFilter = updateInfo.FileFilterGenerator.Filter; - [Test] - public void FileFilterGenerator_Always_ReturnExpectedFileFilter() - { - // Call - string fileFilter = updateInfo.FileFilterGenerator.Filter; + // Assert + Assert.AreEqual(@"Shapebestand (*.shp)|*.shp", fileFilter); + } - // Assert - Assert.AreEqual(@"Shapebestand (*.shp)|*.shp", fileFilter); - } + [Test] + public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - [Test] - public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + const string expectedFilePath = "some/path"; + var structures = new StructureCollection(); + structures.AddRange(Enumerable.Empty(), expectedFilePath); - const string expectedFilePath = "some/path"; - var structures = new StructureCollection(); - structures.AddRange(Enumerable.Empty(), expectedFilePath); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + // Call + string currentPath = updateInfo.CurrentPath(context); - // Call - string currentPath = updateInfo.CurrentPath(context); + // Assert + Assert.AreEqual(expectedFilePath, currentPath); + mocks.VerifyAll(); + } - // Assert - Assert.AreEqual(expectedFilePath, currentPath); - mocks.VerifyAll(); - } + [Test] + public void CreateFileImporter_ValidInput_ReturnFileImporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); - [Test] - public void CreateFileImporter_ValidInput_ReturnFileImporter() + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var importTarget = new StabilityPointStructuresContext(structures, + failureMechanism, + assessmentSection); + + // Call + IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "This is valid"); + + // Assert + Assert.IsInstanceOf(importer); + mocks.VerifyAll(); + } + + [Test] + public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); + + var structures = new StructureCollection(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + bool updatesVerified = updateInfo.VerifyUpdates(context); + + // Assert + Assert.IsTrue(updatesVerified); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + Output = new TestStructuresOutput() + }); - assessmentSection.ReferenceLine = new ReferenceLine(); + var structures = new StructureCollection(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var structures = new StructureCollection(); + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; - var importTarget = new StabilityPointStructuresContext(structures, - failureMechanism, - assessmentSection); + if (isActionConfirmed) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; - // Call - IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "This is valid"); + // Call + bool updatesVerified = updateInfo.VerifyUpdates(context); - // Assert - Assert.IsInstanceOf(importer); - mocks.VerifyAll(); - } + // Assert + string expectedInquiryMessage = "Wanneer de kunstwerken wijzigen als gevolg van het bijwerken " + + "zullen de resultaten van berekeningen die deze kunstwerken gebruiken worden verwijderd." + + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedInquiryMessage, textBoxMessage); + Assert.AreEqual(isActionConfirmed, updatesVerified); + mocks.VerifyAll(); } } } \ No newline at end of file