Index: Core/Common/src/Core.Common.Gui/Commands/GuiUpdateHandler.cs =================================================================== diff -u -r45440093089496f59ed420e772136756c229e30b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Core/Common/src/Core.Common.Gui/Commands/GuiUpdateHandler.cs (.../GuiUpdateHandler.cs) (revision 45440093089496f59ed420e772136756c229e30b) +++ Core/Common/src/Core.Common.Gui/Commands/GuiUpdateHandler.cs (.../GuiUpdateHandler.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -45,14 +45,15 @@ private readonly IWin32Window dialogParent; private readonly IEnumerable updateInfos; - private readonly DialogBasedInquiryHelper inquiryHelper; + private readonly IInquiryHelper inquiryHelper; /// /// Initializes a new instance of the class. /// /// The parent window to show dialogs on top. /// An enumeration of . - public GuiUpdateHandler(IWin32Window dialogParent, IEnumerable updateInfos) + /// + public GuiUpdateHandler(IWin32Window dialogParent, IEnumerable updateInfos, IInquiryHelper inquiryHelper) { if (dialogParent == null) { @@ -64,7 +65,7 @@ } this.dialogParent = dialogParent; this.updateInfos = updateInfos; - inquiryHelper = new DialogBasedInquiryHelper(dialogParent); + this.inquiryHelper = inquiryHelper; } public bool CanUpdateOn(object target) @@ -150,7 +151,7 @@ { log.Info(Resources.GuiImportHandler_ImportItemsUsingDialog_Start_importing_data); - var activity = new FileImportActivity(importer, importName); + var activity = new FileImportActivity(importer, importName ?? string.Empty); ActivityProgressDialogRunner.Run(dialogParent, activity); } } Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -r45440093089496f59ed420e772136756c229e30b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 45440093089496f59ed420e772136756c229e30b) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -27,7 +27,7 @@ using System.Globalization; using System.Linq; using System.Reflection; -using System.Windows; +using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Storage; @@ -47,6 +47,7 @@ using log4net; using log4net.Appender; using log4net.Repository.Hierarchy; +using Application = System.Windows.Application; using SplashScreen = Core.Common.Gui.Forms.SplashScreen.SplashScreen; using WindowsApplication = System.Windows.Forms.Application; @@ -120,7 +121,7 @@ storageCommandHandler = new StorageCommandHandler(projectStore, projectFactory, this, MainWindow); importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos())); exportCommandHandler = new GuiExportHandler(MainWindow, Plugins.SelectMany(p => p.GetExportInfos())); - updateCommandHandler = new GuiUpdateHandler(MainWindow, Plugins.SelectMany(p => p.GetUpdateInfos())); + updateCommandHandler = new GuiUpdateHandler(MainWindow, Plugins.SelectMany(p => p.GetUpdateInfos()), new DialogBasedInquiryHelper(MainWindow)); WindowsApplication.EnableVisualStyles(); ViewPropertyEditor.ViewCommands = ViewCommands; Index: Core/Common/test/Core.Common.Gui.Test/Commands/GuiUpdateHandlerTest.cs =================================================================== diff -u -r45440093089496f59ed420e772136756c229e30b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Core/Common/test/Core.Common.Gui.Test/Commands/GuiUpdateHandlerTest.cs (.../GuiUpdateHandlerTest.cs) (revision 45440093089496f59ed420e772136756c229e30b) +++ Core/Common/test/Core.Common.Gui.Test/Commands/GuiUpdateHandlerTest.cs (.../GuiUpdateHandlerTest.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -21,7 +21,9 @@ using System; using System.Linq; +using System.Threading; using System.Windows.Forms; +using Core.Common.Base.IO; using Core.Common.Gui.Commands; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; @@ -37,12 +39,18 @@ [Test] public void Constructor_WithoutDialogParent_ThrowsArgumentNullException() { + // Setup + var mockRepository = new MockRepository(); + var inquiryHelper = mockRepository.Stub(); + mockRepository.ReplayAll(); + // Call - TestDelegate test = () => new GuiUpdateHandler(null, Enumerable.Empty()); + TestDelegate test = () => new GuiUpdateHandler(null, Enumerable.Empty(), inquiryHelper); // Assert string paramName = Assert.Throws(test).ParamName; Assert.AreEqual("dialogParent", paramName); + mockRepository.VerifyAll(); } [Test] @@ -51,10 +59,11 @@ // Setup var mockRepository = new MockRepository(); var mainWindow = mockRepository.Stub(); + var inquiryHelper = mockRepository.Stub(); mockRepository.ReplayAll(); // Call - TestDelegate test = () => new GuiUpdateHandler(mainWindow, null); + TestDelegate test = () => new GuiUpdateHandler(mainWindow, null, inquiryHelper); // Assert string paramName = Assert.Throws(test).ParamName; @@ -63,77 +72,15 @@ } [Test] - public void UpdateOn_NoUpdaterAvailable_GivesMessageBox() - { - // Setup - var mockRepository = new MockRepository(); - var mainWindow = mockRepository.Stub(); - mockRepository.ReplayAll(); - - string messageBoxTitle = null, messageBoxText = null; - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); - - messageBoxText = messageBox.Text; - messageBoxTitle = messageBox.Title; - - messageBox.ClickOk(); - }; - - var importHandler = new GuiUpdateHandler(mainWindow, Enumerable.Empty()); - - // Call - importHandler.UpdateOn(typeof(long)); - - // Assert - Assert.AreEqual("Fout", messageBoxTitle); - Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText); - mockRepository.VerifyAll(); - } - - [Test] - public void UpdateOn_NoSupportedUpdateInfoAvailable_GivesMessageBox() - { - // Setup - var mockRepository = new MockRepository(); - var mainWindow = mockRepository.Stub(); - mockRepository.ReplayAll(); - - string messageBoxTitle = null, messageBoxText = null; - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); - - messageBoxText = messageBox.Text; - messageBoxTitle = messageBox.Title; - - messageBox.ClickOk(); - }; - - var importHandler = new GuiUpdateHandler(mainWindow, new UpdateInfo[] - { - new UpdateInfo() - }); - - // Call - importHandler.UpdateOn(typeof(long)); - - // Assert - Assert.AreEqual("Fout", messageBoxTitle); - Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText); - mockRepository.VerifyAll(); - } - - [Test] public void CanUpdateOn_HasNoFileUpdatersForTarget_ReturnFalse() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); - var commandHandler = new GuiUpdateHandler(dialogParent, Enumerable.Empty()); + var commandHandler = new GuiUpdateHandler(dialogParent, Enumerable.Empty(), inquiryHelper); // Call bool isImportPossible = commandHandler.CanUpdateOn(new object()); @@ -151,12 +98,13 @@ var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { new UpdateInfo() - }); + }, inquiryHelper); // Call bool isImportPossible = commandHandler.CanUpdateOn(target); @@ -173,6 +121,7 @@ var target = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] @@ -181,7 +130,7 @@ { IsEnabled = data => false } - }); + }, inquiryHelper); // Call bool isImportPossible = commandHandler.CanUpdateOn(target); @@ -198,6 +147,7 @@ var target = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] @@ -210,7 +160,7 @@ { IsEnabled = data => true } - }); + }, inquiryHelper); // Call bool isImportPossible = commandHandler.CanUpdateOn(target); @@ -227,6 +177,7 @@ var target = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] @@ -239,7 +190,7 @@ { IsEnabled = data => false } - }); + }, inquiryHelper); // Call bool isImportPossible = commandHandler.CanUpdateOn(target); @@ -248,5 +199,144 @@ Assert.IsFalse(isImportPossible); mocks.VerifyAll(); } + + [Test] + public void UpdateOn_NoUpdaterAvailable_GivesMessageBox() + { + // Setup + var mockRepository = new MockRepository(); + var mainWindow = mockRepository.Stub(); + var inquiryHelper = mockRepository.Stub(); + mockRepository.ReplayAll(); + + string messageBoxTitle = null, messageBoxText = null; + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + + messageBoxText = messageBox.Text; + messageBoxTitle = messageBox.Title; + + messageBox.ClickOk(); + }; + + var importHandler = new GuiUpdateHandler(mainWindow, Enumerable.Empty(), inquiryHelper); + + // Call + importHandler.UpdateOn(3); + + // Assert + Assert.AreEqual("Fout", messageBoxTitle); + Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText); + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateOn_NoSupportedUpdateInfoAvailable_GivesMessageBox() + { + // Setup + var mockRepository = new MockRepository(); + var mainWindow = mockRepository.Stub(); + var inquiryHelper = mockRepository.Stub(); + mockRepository.ReplayAll(); + + string messageBoxTitle = null, messageBoxText = null; + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + + messageBoxText = messageBox.Text; + messageBoxTitle = messageBox.Title; + + messageBox.ClickOk(); + }; + + var importHandler = new GuiUpdateHandler(mainWindow, new UpdateInfo[] + { + new UpdateInfo() + }, inquiryHelper); + + // Call + importHandler.UpdateOn(string.Empty); + + // Assert + Assert.AreEqual("Fout", messageBoxTitle); + Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText); + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateOn_SupportedUpdateInfoAvailableVerifyUpdatesSuccesful_CreateFileImporterCalled() + { + // Setup + var filter = new ExpectedFile(); + var mockRepository = new MockRepository(); + var inquiryHelper = mockRepository.Stub(); + inquiryHelper.Expect(ih => ih.GetSourceFileLocation(filter)).Return(new FileResult("/some/path")); + IFileImporter fileImporterStub = CreateStubFileImporter(mockRepository); + mockRepository.ReplayAll(); + + DialogBoxHandler = (name, wnd) => + { + // Activity closes itself + }; + + using (var form = new Form()) + { + var importHandler = new GuiUpdateHandler(form, new UpdateInfo[] + { + new UpdateInfo + { + CreateFileImporter = (d, s) => fileImporterStub, + FileFilter = filter, + VerifyUpdates = d => true + } + }, inquiryHelper); + + // Call + importHandler.UpdateOn(3.2); + } + + // Assert + mockRepository.VerifyAll(); + } + + [Test] + public void UpdateOn_SupportedUpdateInfoAvailableVerifyUpdatesUnsuccesful_FileImporterNotCreated() + { + // Setup + var filter = new ExpectedFile(); + var mockRepository = new MockRepository(); + var inquiryHelper = mockRepository.Stub(); + inquiryHelper.Expect(ih => ih.GetSourceFileLocation(filter)).Return(new FileResult("/some/path")); + mockRepository.ReplayAll(); + + using (var form = new Form()) + { + var importHandler = new GuiUpdateHandler(form, new UpdateInfo[] + { + new UpdateInfo + { + FileFilter = filter, + VerifyUpdates = d => false + } + }, inquiryHelper); + + // Call + importHandler.UpdateOn(3.2); + } + + // Assert + mockRepository.VerifyAll(); + } + + private static IFileImporter CreateStubFileImporter(MockRepository mockRepository) + { + var fileImporterStub = mockRepository.Stub(); + fileImporterStub.Expect(fi => fi.Import()); + fileImporterStub.Expect(fi => fi.DoPostImport()); + fileImporterStub.Expect(fi => fi.SetProgressChanged(null)).IgnoreArguments(); + return fileImporterStub; + } } } \ No newline at end of file Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -r8c8285c58f677a2905127f1c3576eb7d6ea4206b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 8c8285c58f677a2905127f1c3576eb7d6ea4206b) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -557,7 +557,7 @@ var soilProfilesImporter = new StochasticSoilModelImporter(pipingFailureMechanism.StochasticSoilModels, Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil"), - new StochasticSoilModelReplaceDataStrategy()); + new StochasticSoilModelReplaceDataStrategy(pipingFailureMechanism)); soilProfilesImporter.Import(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/DataImportHelper.cs =================================================================== diff -u -r8c8285c58f677a2905127f1c3576eb7d6ea4206b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/DataImportHelper.cs (.../DataImportHelper.cs) (revision 8c8285c58f677a2905127f1c3576eb7d6ea4206b) +++ Ringtoets/Integration/test/Ringtoets.Integration.TestUtils/DataImportHelper.cs (.../DataImportHelper.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -212,7 +212,7 @@ var activity = new FileImportActivity(new StochasticSoilModelImporter( assessmentSection.PipingFailureMechanism.StochasticSoilModels, filePath, - new StochasticSoilModelReplaceDataStrategy()), + new StochasticSoilModelReplaceDataStrategy(assessmentSection.PipingFailureMechanism)), "StochasticSoilModelImporter"); activity.Run(); activity.Finish(); Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs =================================================================== diff -u -r8c8285c58f677a2905127f1c3576eb7d6ea4206b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision 8c8285c58f677a2905127f1c3576eb7d6ea4206b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -26,6 +26,7 @@ using log4net; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Importers; +using Ringtoets.Piping.Service; namespace Ringtoets.Piping.Plugin.FileImporter { @@ -36,6 +37,21 @@ { private readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilModelReplaceDataStrategy)); + private readonly PipingFailureMechanism failureMechanism; + + /// + /// Creates a new instance of . + /// + /// The failure mechanism in which the models are updated. + public StochasticSoilModelReplaceDataStrategy(PipingFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + this.failureMechanism = failureMechanism; + } + public IEnumerable UpdateModelWithImportedData(ObservableCollectionWithSourcePath targetCollection, IEnumerable readStochasticSoilModels, string sourceFilePath) @@ -53,6 +69,11 @@ throw new ArgumentNullException(nameof(sourceFilePath)); } + var affectedObjects = new List + { + targetCollection + }; + var modelsToAdd = new List(); foreach (StochasticSoilModel readStochasticSoilModel in readStochasticSoilModels) { @@ -63,11 +84,12 @@ } modelsToAdd.Add(readStochasticSoilModel); } - targetCollection.AddRange(modelsToAdd, sourceFilePath); - return new[] + foreach (StochasticSoilModel model in targetCollection.ToArray()) { - targetCollection - }; + affectedObjects.AddRange(PipingDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, model)); + } + targetCollection.AddRange(modelsToAdd, sourceFilePath); + return affectedObjects; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r8c8285c58f677a2905127f1c3576eb7d6ea4206b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 8c8285c58f677a2905127f1c3576eb7d6ea4206b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -119,7 +119,7 @@ Image = PipingFormsResources.PipingSoilProfileIcon, FileFilter = StochasticSoilModelFileFilter, IsEnabled = StochasticSoilModelImporterEnabled, - CreateFileImporter = (context, filePath) => StochasticSoilModelImporter(context, filePath, new StochasticSoilModelReplaceDataStrategy()), + CreateFileImporter = (context, filePath) => StochasticSoilModelImporter(context, filePath, new StochasticSoilModelReplaceDataStrategy(context.FailureMechanism)), VerifyUpdates = VerifyStochasticSoilModelUpdates }; } Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs =================================================================== diff -u -r8c8285c58f677a2905127f1c3576eb7d6ea4206b -rf96e01d46f29a268ab62fc6afe5b23f311e63a39 --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs (.../ImportSoilProfileFromDatabaseTest.cs) (revision 8c8285c58f677a2905127f1c3576eb7d6ea4206b) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/ImportSoilProfileFromDatabaseTest.cs (.../ImportSoilProfileFromDatabaseTest.cs) (revision f96e01d46f29a268ab62fc6afe5b23f311e63a39) @@ -49,7 +49,7 @@ var importer = new StochasticSoilModelImporter( pipingFailureMechanism.StochasticSoilModels, databasePath, - new StochasticSoilModelReplaceDataStrategy()); + new StochasticSoilModelReplaceDataStrategy(pipingFailureMechanism)); importer.Import(); // Then @@ -89,7 +89,7 @@ var importer = new StochasticSoilModelImporter( pipingFailureMechanism.StochasticSoilModels, databasePath, - new StochasticSoilModelReplaceDataStrategy()); + new StochasticSoilModelReplaceDataStrategy(pipingFailureMechanism)); importer.Import(); // Then @@ -125,7 +125,7 @@ var importer = new StochasticSoilModelImporter( pipingFailureMechanism.StochasticSoilModels, databasePath, - new StochasticSoilModelReplaceDataStrategy()); + new StochasticSoilModelReplaceDataStrategy(pipingFailureMechanism)); importer.Import(); // Then