Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -r485d2b4c361dc629baad519310d6758919bf86e1 -r034ce0301351fb0c587bc150782a7e7c4e2c000d --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 485d2b4c361dc629baad519310d6758919bf86e1) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 034ce0301351fb0c587bc150782a7e7c4e2c000d) @@ -577,12 +577,25 @@ return new StrictContextMenuItem(RingtoetsCommonFormsResources.StructuresPlugin_CreateUpdateStructureItem_Update_all_Structures, toolTipText, RingtoetsCommonFormsResources.UpdateItemIcon, - (o, args) => { }) + (o, args) => { UpdateStructureDependentDataOfCalculation(calculations); }) { Enabled = contextMenuEnabled }; } + private void UpdateStructureDependentDataOfCalculation(IEnumerable> calculations) + { + string message = + RingtoetsCommonFormsResources.StructuresPlugin_VerifyStructureUpdate_Confirm_calculation_outputs_cleared_when_updating_Structure_dependent_data; + if (StructureDependentDataShouldUpdate(calculations, message)) + { + foreach (StructuresCalculation calculation in calculations) + { + UpdateStructureDerivedCalculationInput(calculation); + } + } + } + private StrictContextMenuItem CreateGenerateClosingStructuresCalculationsItem(ClosingStructuresCalculationGroupContext nodeData) { bool structuresAvailable = nodeData.FailureMechanism.ClosingStructures.Any(); Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r485d2b4c361dc629baad519310d6758919bf86e1 -r034ce0301351fb0c587bc150782a7e7c4e2c000d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 485d2b4c361dc629baad519310d6758919bf86e1) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 034ce0301351fb0c587bc150782a7e7c4e2c000d) @@ -19,11 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; using Core.Common.Controls.TreeView; @@ -44,6 +46,7 @@ using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms; @@ -707,8 +710,6 @@ mocks.ReplayAll(); - plugin.Gui = gui; - DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed @@ -784,8 +785,6 @@ mocks.ReplayAll(); - plugin.Gui = gui; - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Call @@ -906,8 +905,8 @@ var assessmentSection = mocks.Stub(); var nodeData = new ClosingStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSection); + failureMechanism, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -942,8 +941,8 @@ var failureMechanism = new ClosingStructuresFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new ClosingStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSection); + failureMechanism, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -984,8 +983,8 @@ var failureMechanism = new ClosingStructuresFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new ClosingStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSection); + failureMechanism, + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -1005,6 +1004,300 @@ } [Test] + public void GivenCalculationWithStructureWithOutput_WhenStructureHasChangesAndUpdateClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + // Given + var assessmentSection = mocks.Stub(); + var structure = new TestClosingStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + + ClosingStructuresInput calculationInput = calculation.InputParameters; + + RoundedDouble expectedStructureNormalOrientation = calculationInput.StructureNormalOrientation; + NormalDistribution expectedLevelCrestStructureNotClosing = calculationInput.LevelCrestStructureNotClosing; + LogNormalDistribution expectedFlowWidthAtBottomProtection = calculationInput.FlowWidthAtBottomProtection; + VariationCoefficientLogNormalDistribution expectedCriticalOvertoppingDischarge = calculationInput.CriticalOvertoppingDischarge; + NormalDistribution expectedWidthFlowApertures = calculationInput.WidthFlowApertures; + VariationCoefficientLogNormalDistribution expectedStorageStructureArea = calculationInput.StorageStructureArea; + LogNormalDistribution expectedAllowedLevelIncreaseStorage = calculationInput.AllowedLevelIncreaseStorage; + ClosingStructureInflowModelType expectedInflowModelType = calculationInput.InflowModelType; + LogNormalDistribution expectedAreaFlowApertures = calculationInput.AreaFlowApertures; + double expectedFailureProbabilityOpenStructure = calculationInput.FailureProbabilityOpenStructure; + double expectedFailureProbabilityReparation = calculationInput.FailureProbabilityReparation; + int expectedIdenticalApertures = calculationInput.IdenticalApertures; + NormalDistribution expectedInsideWaterLevel = calculationInput.InsideWaterLevel; + double expectedProbabilityOrFrequencyOpenStructureBeforeFlooding = calculationInput.ProbabilityOrFrequencyOpenStructureBeforeFlooding; + NormalDistribution expectedThresholdHeightOpenWeir = calculationInput.ThresholdHeightOpenWeir; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculationInput.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateStructure(structure); + menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + + Assert.AreSame(structure, calculationInput.Structure); + + Assert.AreEqual(expectedStructureNormalOrientation, calculationInput.StructureNormalOrientation); + Assert.AreEqual(expectedLevelCrestStructureNotClosing, calculationInput.LevelCrestStructureNotClosing); + Assert.AreEqual(expectedFlowWidthAtBottomProtection, calculationInput.FlowWidthAtBottomProtection); + Assert.AreEqual(expectedCriticalOvertoppingDischarge, calculationInput.CriticalOvertoppingDischarge); + Assert.AreEqual(expectedWidthFlowApertures, calculationInput.WidthFlowApertures); + Assert.AreEqual(expectedStorageStructureArea, calculationInput.StorageStructureArea); + Assert.AreEqual(expectedAllowedLevelIncreaseStorage, calculationInput.AllowedLevelIncreaseStorage); + Assert.AreEqual(expectedInflowModelType, calculationInput.InflowModelType); + Assert.AreEqual(expectedAreaFlowApertures, calculationInput.AreaFlowApertures); + Assert.AreEqual(expectedFailureProbabilityOpenStructure, calculationInput.FailureProbabilityOpenStructure); + Assert.AreEqual(expectedFailureProbabilityReparation, calculationInput.FailureProbabilityReparation); + Assert.AreEqual(expectedIdenticalApertures, calculationInput.IdenticalApertures); + Assert.AreEqual(expectedInsideWaterLevel, calculationInput.InsideWaterLevel); + Assert.AreEqual(expectedProbabilityOrFrequencyOpenStructureBeforeFlooding, calculationInput.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + Assert.AreEqual(expectedThresholdHeightOpenWeir, calculationInput.ThresholdHeightOpenWeir); + + string expectedMessage = "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(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithStructureWithOutput_WhenStructureHasChangesUpdateStructureClickedAndContinued_ThenInquiryAndUpdatesCalculationAndObserversNotified() + { + // Given + var assessmentSection = mocks.Stub(); + var structure = new TestClosingStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(obs => obs.UpdateObserver()); + calculation.Attach(calculationObserver); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + UpdateStructure(structure); + menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + + AssertClosingStructuresInput(structure, calculation.InputParameters); + + string expectedMessage = "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(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithStructureWithOutput_WhenStructureHasNoChangeAndUpdateClickedAndContinued_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + // Given + var assessmentSection = mocks.Stub(); + + var structure = new TestClosingStructure(); + UpdateStructure(structure); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + + var inputObserver = mocks.StrictMock(); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + + AssertClosingStructuresInput(structure, calculation.InputParameters); + + string expectedMessage = "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(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithStructureWithOutput_WhenStructurePartiallyDifferentAndUpdateClicked_ThenInquiryAndUpdatesCalculationAndNotifiesObserver() + { + // Given + var assessmentSection = mocks.Stub(); + + var structure = new TestClosingStructure(); + UpdateStructure(structure); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(obs => obs.UpdateObserver()); + calculation.Attach(calculationObserver); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + ClosingStructuresInput inputParameters = calculation.InputParameters; + inputParameters.StructureNormalOrientation = (RoundedDouble) 1.1; + menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + Assert.AreEqual(structure.StructureNormalOrientation, inputParameters.StructureNormalOrientation); + + string expectedMessage = "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(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenClosingStructureSelectedAndDialogClosed_ThenCalculationsAddedWithClosingStructureAssigned() { // Given @@ -1047,8 +1340,6 @@ mocks.ReplayAll(); - plugin.Gui = gui; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; @@ -1106,8 +1397,6 @@ mocks.ReplayAll(); - plugin.Gui = gui; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; @@ -1155,7 +1444,7 @@ }; failureMechanism.ClosingStructures.AddRange(new[] { - closingStructure, + closingStructure }, "some path"); var nodeData = new ClosingStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, @@ -1171,8 +1460,6 @@ mocks.ReplayAll(); - plugin.Gui = gui; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; @@ -1302,5 +1589,89 @@ // Assert CollectionAssert.DoesNotContain(parentGroup.Children, group); } + + private static void UpdateStructure(ClosingStructure structure) + { + var structureToUpdateFrom = new ClosingStructure( + new ClosingStructure.ConstructionProperties + { + Id = structure.Id, + Name = structure.Name, + Location = structure.Location, + StructureNormalOrientation = (RoundedDouble) 1.0, + LevelCrestStructureNotClosing = + { + Mean = (RoundedDouble) 2.0, + StandardDeviation = (RoundedDouble) 3.0 + }, + FlowWidthAtBottomProtection = + { + Mean = (RoundedDouble) 4.0, + StandardDeviation = (RoundedDouble) 5.0 + }, + CriticalOvertoppingDischarge = + { + Mean = (RoundedDouble) 6.0, + CoefficientOfVariation = (RoundedDouble) 7.0 + }, + WidthFlowApertures = + { + Mean = (RoundedDouble) 8.0, + StandardDeviation = (RoundedDouble) 9.0 + }, + StorageStructureArea = + { + Mean = (RoundedDouble) 10.0, + CoefficientOfVariation = (RoundedDouble) 11.0 + }, + AllowedLevelIncreaseStorage = + { + Mean = (RoundedDouble) 12.0, + StandardDeviation = (RoundedDouble) 13.0 + }, + InflowModelType = ClosingStructureInflowModelType.FloodedCulvert, + AreaFlowApertures = + { + Mean = (RoundedDouble) 14.0, + StandardDeviation = (RoundedDouble) 15.0 + }, + FailureProbabilityOpenStructure = 0.16, + FailureProbabilityReparation = 0.17, + IdenticalApertures = 18, + InsideWaterLevel = + { + Mean = (RoundedDouble) 19.0, + StandardDeviation = (RoundedDouble) 20.0 + }, + ProbabilityOrFrequencyOpenStructureBeforeFlooding = 0.21, + ThresholdHeightOpenWeir = + { + Mean = (RoundedDouble) 22.0, + StandardDeviation = (RoundedDouble) 23.0 + } + }); + + structure.CopyProperties(structureToUpdateFrom); + } + + private static void AssertClosingStructuresInput(TestClosingStructure structure, ClosingStructuresInput inputParameters) + { + Assert.AreSame(structure, inputParameters.Structure); + Assert.AreEqual(structure.StructureNormalOrientation, inputParameters.StructureNormalOrientation); + Assert.AreEqual(structure.LevelCrestStructureNotClosing, inputParameters.LevelCrestStructureNotClosing); + Assert.AreEqual(structure.FlowWidthAtBottomProtection, inputParameters.FlowWidthAtBottomProtection); + Assert.AreEqual(structure.CriticalOvertoppingDischarge, inputParameters.CriticalOvertoppingDischarge); + Assert.AreEqual(structure.WidthFlowApertures, inputParameters.WidthFlowApertures); + Assert.AreEqual(structure.StorageStructureArea, inputParameters.StorageStructureArea); + Assert.AreEqual(structure.AllowedLevelIncreaseStorage, inputParameters.AllowedLevelIncreaseStorage); + Assert.AreEqual(structure.InflowModelType, inputParameters.InflowModelType); + Assert.AreEqual(structure.AreaFlowApertures, inputParameters.AreaFlowApertures); + Assert.AreEqual(structure.FailureProbabilityOpenStructure, inputParameters.FailureProbabilityOpenStructure); + Assert.AreEqual(structure.FailureProbabilityReparation, inputParameters.FailureProbabilityReparation); + Assert.AreEqual(structure.IdenticalApertures, inputParameters.IdenticalApertures); + Assert.AreEqual(structure.InsideWaterLevel, inputParameters.InsideWaterLevel); + Assert.AreEqual(structure.ProbabilityOrFrequencyOpenStructureBeforeFlooding, inputParameters.ProbabilityOrFrequencyOpenStructureBeforeFlooding); + Assert.AreEqual(structure.ThresholdHeightOpenWeir, inputParameters.ThresholdHeightOpenWeir); + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r9406843bc73c4d96aa587eecd7e63831ca1d106c -r034ce0301351fb0c587bc150782a7e7c4e2c000d --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 9406843bc73c4d96aa587eecd7e63831ca1d106c) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 034ce0301351fb0c587bc150782a7e7c4e2c000d) @@ -867,8 +867,6 @@ assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; - plugin.Gui = guiStub; - DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed @@ -944,8 +942,6 @@ mocks.ReplayAll(); - plugin.Gui = guiStub; - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Call @@ -1192,13 +1188,10 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); - plugin.Gui = gui; - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When @@ -1272,12 +1265,10 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); - plugin.Gui = gui; using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When @@ -1347,13 +1338,10 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); - plugin.Gui = gui; - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When @@ -1426,13 +1414,10 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); - plugin.Gui = gui; - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When @@ -1506,13 +1491,10 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + guiStub.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiStub.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); - plugin.Gui = gui; - using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) { // When @@ -1577,8 +1559,6 @@ mocks.ReplayAll(); - plugin.Gui = guiStub; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; @@ -1635,8 +1615,6 @@ mocks.ReplayAll(); - plugin.Gui = guiStub; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; @@ -1701,8 +1679,6 @@ mocks.ReplayAll(); - plugin.Gui = guiStub; - DialogBoxHandler = (name, wnd) => { var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject;