Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs =================================================================== diff -u -r6ce3cfa19ef59b12462bae4a77e9a7ee5a05e28c -r87152abf42288bdf4c05e2621b8bd10562e61192 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs (.../StochasticSoilModelCollectionContextTreeNodeInfoTest.cs) (revision 6ce3cfa19ef59b12462bae4a77e9a7ee5a05e28c) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs (.../StochasticSoilModelCollectionContextTreeNodeInfoTest.cs) (revision 87152abf42288bdf4c05e2621b8bd10562e61192) @@ -41,6 +41,7 @@ using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.KernelWrapper.TestUtil; using Ringtoets.Piping.Primitives; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsPipingPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; @@ -336,15 +337,8 @@ pipingFailureMechanism, assessmentSection); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - var mainWindow = mocks.Stub(); + IGui gui = CreateGuiStub(nodeData, treeViewControl); - var gui = mocks.Stub(); - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mainWindow); - mocks.ReplayAll(); - plugin.Gui = gui; DialogBoxHandler = (name, wnd) => @@ -378,22 +372,13 @@ { var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); - var stochasticSoilModelCollection = new ObservableCollectionWithSourcePath(); - stochasticSoilModelCollection.AddRange(Enumerable.Empty(), existingFilePath); - var nodeData = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, + var nodeData = new StochasticSoilModelCollectionContext(CreateEmptyImportedStochasticSoilModelCollection(existingFilePath), pipingFailureMechanism, assessmentSection); - var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - var mainWindow = mocks.Stub(); + IGui gui = CreateGuiStub(nodeData, treeViewControl); - var gui = mocks.Stub(); - gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); - gui.Stub(g => g.MainWindow).Return(mainWindow); - mocks.ReplayAll(); - plugin.Gui = gui; DialogBoxHandler = (s, hWnd) => @@ -413,5 +398,119 @@ } } } + + [Test] + [Apartment(ApartmentState.STA)] + public void ContextMenuStrip_ClickOnUpdateStochasticSoilModelsPathKnownAndConfirmationRequiredAndGiven_SuccessMessageLogged() + { + // Setup + string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "StochasticSoilModelDatabaseReader"); + string existingFilePath = Path.Combine(testDirectory, "emptyschema.soil"); + + using (var treeViewControl = new TreeViewControl()) + { + var pipingFailureMechanism = new PipingFailureMechanism(); + MakeConfirmationRequired(pipingFailureMechanism); + + var assessmentSection = mocks.Stub(); + + var nodeData = new StochasticSoilModelCollectionContext(CreateEmptyImportedStochasticSoilModelCollection(existingFilePath), + pipingFailureMechanism, + assessmentSection); + + IGui gui = CreateGuiStub(nodeData, treeViewControl); + + plugin.Gui = gui; + + DialogBoxHandler = (name, handler) => + { + DialogBoxHandler = (activityName, activityHandler) => + { + // Activity dialog closes by itself + }; + + var tester = new MessageBoxTester(handler); + tester.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + Action test = () => menu.Items[updateStochasticSoilModelsItemIndex].PerformClick(); + + // Assert + TestHelper.AssertLogMessageIsGenerated( + test, + "Uitvoeren van 'Bijwerken van stochastische ondergrondmodellen.' is gelukt."); + } + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ContextMenuStrip_ClickOnUpdateStochasticSoilModelsPathKnownAndConfirmationRequiredButNotGiven_CancelMessageLogged() + { + // Setup + string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "StochasticSoilModelDatabaseReader"); + string existingFilePath = Path.Combine(testDirectory, "emptyschema.soil"); + + using (var treeViewControl = new TreeViewControl()) + { + var pipingFailureMechanism = new PipingFailureMechanism(); + MakeConfirmationRequired(pipingFailureMechanism); + + var assessmentSection = mocks.Stub(); + + var nodeData = new StochasticSoilModelCollectionContext(CreateEmptyImportedStochasticSoilModelCollection(existingFilePath), + pipingFailureMechanism, + assessmentSection); + + IGui gui = CreateGuiStub(nodeData, treeViewControl); + + plugin.Gui = gui; + + DialogBoxHandler = (name, handler) => + { + var tester = new MessageBoxTester(handler); + tester.ClickCancel(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + Action test = () => menu.Items[updateStochasticSoilModelsItemIndex].PerformClick(); + + // Assert + TestHelper.AssertLogMessageIsGenerated( + test, + $"Bijwerken van ondergrondschematisaties in '{existingFilePath}' is door de gebruiker geannuleerd."); + } + } + } + + private static ObservableCollectionWithSourcePath CreateEmptyImportedStochasticSoilModelCollection(string existingFilePath) + { + var stochasticSoilModelCollection = new ObservableCollectionWithSourcePath(); + stochasticSoilModelCollection.AddRange(Enumerable.Empty(), existingFilePath); + return stochasticSoilModelCollection; + } + + private static void MakeConfirmationRequired(PipingFailureMechanism pipingFailureMechanism) + { + pipingFailureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) + { + Output = new TestPipingOutput() + }); + } + + private IGui CreateGuiStub(StochasticSoilModelCollectionContext nodeData, TreeViewControl treeViewControl) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + return gui; + } } } \ No newline at end of file