Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r3d95e2d4d19772aab17604346c7a6def74bb1192 -reda792edf991acda76154e8f2d4802944cea1e25 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision eda792edf991acda76154e8f2d4802944cea1e25) @@ -56,9 +56,10 @@ public class StabilityPointStructuresCalculationContextTreeNodeInfoTest : NUnitFormTest { private const int contextMenuUpdateForeshoreProfileIndex = 3; - private const int contextMenuValidateIndex = 5; - private const int contextMenuCalculateIndex = 6; - private const int contextMenuClearIndex = 8; + private const int contextMenuUpdateStructureIndex = 4; + private const int contextMenuValidateIndex = 6; + private const int contextMenuCalculateIndex = 7; + private const int contextMenuClearIndex = 9; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private MockRepository mocks; @@ -186,6 +187,7 @@ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -247,14 +249,20 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSectionStub, treeViewControl)) { // Assert - Assert.AreEqual(15, menu.Items.Count); + Assert.AreEqual(16, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndex, "&Bijwerken voorlandprofiel...", "Er moet een voorlandprofiel geselecteerd zijn.", RingtoetsCommonFormsResources.UpdateItemIcon, false); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er moet een kunstwerk geselecteerd zijn.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, "&Valideren", "Valideer de invoer voor deze berekening.", @@ -275,6 +283,294 @@ } [Test] + public void ContextMenuStrip_CalculationWithoutStructure_ContextMenuItemUpdateStructureDisabledAndToolTipSet() + { + // Setup + var assessmentSection = mocks.Stub(); + + var calculation = new StructuresCalculation(); + var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er moet een kunstwerk geselecteerd zijn.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithStructureAndInputInSync_ContextMenuItemUpdateStructureDisabledAndToolTipSet() + { + // Setup + var assessmentSection = mocks.Stub(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestStabilityPointStructure() + } + }; + var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er zijn geen wijzigingen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithStructureAndInputOutOfSync_ContextMenuItemUpdateStructureEnabledAndToolTipSet() + { + // Setup + var assessmentSection = mocks.Stub(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestStabilityPointStructure() + } + }; + var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + ChangeStructure(calculation.InputParameters.Structure); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Berekening bijwerken met het kunstwerk.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructureClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + calculationInputObserver.Expect(o => o.UpdateObserver()); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestStabilityPointStructure() + } + }; + var nodeData = new StabilityPointStructuresCalculationContext(calculation, + failureMechanism, + assessmentSection); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeStructure(calculation.InputParameters.Structure); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized); + } + } + } + + [Test] + public void GivenCalculationWithOutputAndInputInSync_WhenUpdateStructureClicked_ThenNoInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + // Given + var assessmentSection = mocks.Stub(); + var structure = new TestStabilityPointStructure(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + + StabilityPointStructuresInput calculationInput = calculation.InputParameters; + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculationInput.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GivenCalculationWithOutputAndWithInputOutOfSync_WhenUpdateStructureClicked_ThenInquiryAndExpectedOutputAndNotifications(bool continuation) + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + var assessmentSectionStub = mocks.Stub(); + var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestStabilityPointStructure() + }, + Output = new TestStructuresOutput() + }; + + var nodeData = new StabilityPointStructuresCalculationContext(calculation, + failureMechanism, + assessmentSectionStub); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + if (continuation) + { + calculationObserver.Expect(o => o.UpdateObserver()); + calculationInputObserver.Expect(o => o.UpdateObserver()); + } + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + if (continuation) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeStructure(calculation.InputParameters.Structure); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.AreEqual(continuation, calculation.InputParameters.IsStructureInputSynchronized); + Assert.AreEqual(!continuation, calculation.HasOutput); + } + } + + string expectedMessageBoxText = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + Assert.AreEqual(expectedMessageBoxText, messageBoxText); + } + + [Test] public void ContextMenuStrip_NoHydraulicBoundaryDatabase_ContextMenuItemPerformCalculationAndValidationDisabledAndTooltipSet() { // Setup @@ -443,7 +739,7 @@ [Test] [Combinatorial] - public void ContextMenuStripm_ForeshoreProfileStates_CreatesExpectedItem( + public void ContextMenuStrip_ForeshoreProfileStates_CreatesExpectedItem( [Values(true, false)] bool hasForeshoreProfile, [Values(true, false)] bool isSynchronized) { @@ -564,7 +860,7 @@ [Test] [TestCase(true)] [TestCase(false)] - public void GivenCalculationWithOutputAndWithInputOutOfSync_WhenPerformClick_ThenInquiryAndExpectedOutputAndNotifications(bool continuation) + public void GivenCalculationWithOutputAndWithInputOutOfSync_WhenUpdateForeshoreProfileClicked_ThenInquiryAndExpectedOutputAndNotifications(bool continuation) { // Given var calculationObserver = mocks.StrictMock(); @@ -855,5 +1151,16 @@ base.TearDown(); } + + private static void ChangeStructure(StabilityPointStructure structure) + { + structure.CopyProperties(new StabilityPointStructure( + new StabilityPointStructure.ConstructionProperties + { + Id = structure.Id, + Name = structure.Name, + Location = structure.Location + })); + } } } \ No newline at end of file