Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rc2f37ea8bfc69b7faf9ceb42adab29b658599af9 -r9ac9793e704fce8e72b49a0575c47ae1628044af --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision c2f37ea8bfc69b7faf9ceb42adab29b658599af9) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision 9ac9793e704fce8e72b49a0575c47ae1628044af) @@ -1529,7 +1529,7 @@ } [Test] - public void GivenCalculationsInNestedGroupWithoutOutput_WhenSurfaceLineChangedAndUpdateClicked_ThenCalculationsUpdatedAndObserversNotified() + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateEntryAndExitPointsClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1627,7 +1627,7 @@ } [Test] - public void GivenCalculationsInNestedGroupWithOutput_WhenSurfaceLineChangedAndUpdateClickedAndContinued_ThenCalculationsUpdatedAndObserversNotified() + public void GivenCalculationWithOutputAndInputInSync_WhenUpdateEntryAndExitPointsClicked_ThenNoInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1637,11 +1637,6 @@ var calculation2Observer = mocks.StrictMock(); var calculation2InputObserver = mocks.StrictMock(); - calculation1Observer.Expect(obs => obs.UpdateObserver()); - calculation1InputObserver.Expect(obs => obs.UpdateObserver()); - calculation2Observer.Expect(obs => obs.UpdateObserver()); - calculation2InputObserver.Expect(obs => obs.UpdateObserver()); - var surfaceLine = new RingtoetsPipingSurfaceLine(); surfaceLine.SetGeometry(new[] { @@ -1653,9 +1648,7 @@ { InputParameters = { - SurfaceLine = surfaceLine, - EntryPointL = (RoundedDouble) 0, - ExitPointL = (RoundedDouble) 1 + SurfaceLine = surfaceLine }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() @@ -1667,9 +1660,7 @@ { InputParameters = { - SurfaceLine = surfaceLine, - EntryPointL = (RoundedDouble) 0, - ExitPointL = (RoundedDouble) 1 + SurfaceLine = surfaceLine }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() @@ -1714,36 +1705,22 @@ plugin.Gui = gui; - string textBoxMessage = null; - DialogBoxHandler = (name, wnd) => - { - var helper = new MessageBoxTester(wnd); - textBoxMessage = helper.Text; - helper.ClickOk(); - }; - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When - ChangeSurfaceLine(surfaceLine); - contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); // Then - Assert.IsFalse(calculation1.HasOutput); + Assert.IsTrue(calculation1.HasOutput); Assert.IsTrue(calculation1.InputParameters.IsEntryAndExitPointInputSynchronized); - Assert.IsFalse(calculation2.HasOutput); + Assert.IsTrue(calculation2.HasOutput); Assert.IsTrue(calculation2.InputParameters.IsEntryAndExitPointInputSynchronized); - - string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + - $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; - Assert.AreEqual(expectedMessage, textBoxMessage); } } } [Test] - public void GivenCalculationsInNestedGroupWithOutput_WhenSurfaceLineChangedAndUpdateClickedAndCancelled_ThenCalculationsNotUpdated() + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointsClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1854,7 +1831,7 @@ } [Test] - public void GivenCalculationsInNestedGroupWithoutOutput_WhenUpdatedEntryAndExitPoints_ThenNoInquiryAndCalculationsUpdatedAndObserversNotified() + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointsClickedAndContinued_ThenInquiryAndUpdatesCalculationAndObserversNotified() { // Setup using (var treeViewControl = new TreeViewControl()) @@ -1864,6 +1841,11 @@ var calculation2Observer = mocks.StrictMock(); var calculation2InputObserver = mocks.StrictMock(); + calculation1Observer.Expect(obs => obs.UpdateObserver()); + calculation1InputObserver.Expect(obs => obs.UpdateObserver()); + calculation2Observer.Expect(obs => obs.UpdateObserver()); + calculation2InputObserver.Expect(obs => obs.UpdateObserver()); + var surfaceLine = new RingtoetsPipingSurfaceLine(); surfaceLine.SetGeometry(new[] { @@ -1876,9 +1858,11 @@ InputParameters = { SurfaceLine = surfaceLine, - EntryPointL = (RoundedDouble) 2, - ExitPointL = (RoundedDouble) 3 - } + EntryPointL = (RoundedDouble) 0, + ExitPointL = (RoundedDouble) 1 + }, + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation1.Attach(calculation1Observer); calculation1.InputParameters.Attach(calculation1InputObserver); @@ -1888,9 +1872,11 @@ InputParameters = { SurfaceLine = surfaceLine, - EntryPointL = (RoundedDouble) 2, - ExitPointL = (RoundedDouble) 3 - } + EntryPointL = (RoundedDouble) 0, + ExitPointL = (RoundedDouble) 1 + }, + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation2.Attach(calculation2Observer); calculation2.InputParameters.Attach(calculation2InputObserver); @@ -1932,6 +1918,14 @@ plugin.Gui = gui; + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When @@ -1941,17 +1935,13 @@ // Then Assert.IsFalse(calculation1.HasOutput); + Assert.IsTrue(calculation1.InputParameters.IsEntryAndExitPointInputSynchronized); Assert.IsFalse(calculation2.HasOutput); + Assert.IsTrue(calculation2.InputParameters.IsEntryAndExitPointInputSynchronized); - PipingInput inputParameters1 = calculation1.InputParameters; - Assert.AreSame(surfaceLine, inputParameters1.SurfaceLine); - Assert.AreEqual(new RoundedDouble(2, 2), inputParameters1.EntryPointL); - Assert.AreEqual(new RoundedDouble(3, 3), inputParameters1.ExitPointL); - - PipingInput inputParameters2 = calculation2.InputParameters; - Assert.AreSame(surfaceLine, inputParameters2.SurfaceLine); - Assert.AreEqual(new RoundedDouble(2, 2), inputParameters2.EntryPointL); - Assert.AreEqual(new RoundedDouble(3, 3), inputParameters2.ExitPointL); + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); } } } Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rc2f37ea8bfc69b7faf9ceb42adab29b658599af9 -r9ac9793e704fce8e72b49a0575c47ae1628044af --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision c2f37ea8bfc69b7faf9ceb42adab29b658599af9) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision 9ac9793e704fce8e72b49a0575c47ae1628044af) @@ -524,7 +524,7 @@ } [Test] - public void GivenCalculationWithSurfaceLineWithoutOutput_WhenSurfaceLineChangedAndUpdateClicked_ThenNoInquiryAndPointsUpdatedAndObserversNotified() + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateEntryAndExitPointClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { using (var treeViewControl = new TreeViewControl()) { @@ -573,11 +573,70 @@ } [Test] - public void GivenCalculationWithSurfaceLineAndOutput_WhenSurfaceLineChangedAndUpdateClickedAndContinued_ThenPointsUpdatedOutputsRemovedAndObserversNotified() + public void GivenCalculationWithOutputAndInputInSync_WhenUpdateEntryAndExitPointClicked_ThenNoInquiryAndCalculationNotUpdatedAndObserversNotNotified() { using (var treeViewControl = new TreeViewControl()) { // Given + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + }, + Output = new TestPipingOutput(), + SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() + }; + + var pipingFailureMechanism = new TestPipingFailureMechanism(); + var assessmentSection = mocks.Stub(); + var nodeData = new PipingCalculationScenarioContext(calculation, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + 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); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsEntryAndExitPointInputSynchronized); + + // Note: observer assertions are verified in TearDown + } + } + } + + [Test] + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given RingtoetsPipingSurfaceLine surfaceLine; PipingCalculationScenario calculation; CreateCalculationWithSurfaceLine(out calculation, out surfaceLine); @@ -592,11 +651,9 @@ 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); var mainWindow = mocks.Stub(); @@ -612,7 +669,7 @@ { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; - helper.ClickOk(); + helper.ClickCancel(); }; ChangeSurfaceLine(surfaceLine); @@ -623,8 +680,8 @@ contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); // Then - Assert.IsFalse(calculation.HasOutput); - Assert.IsTrue(calculation.InputParameters.IsEntryAndExitPointInputSynchronized); + Assert.IsTrue(calculation.HasOutput); + Assert.IsFalse(calculation.InputParameters.IsEntryAndExitPointInputSynchronized); string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; @@ -636,7 +693,7 @@ } [Test] - public void GivenCalculationWithSurfaceLineAndOutput_WhenSurfaceLineChangedAndUpdateClickedAndCancelled_ThenCalculationNotUpdatedAndObserversNotUpdated() + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointClickedAndContinued_ThenInquiryAndUpdatesCalculationAndObserversNotified() { using (var treeViewControl = new TreeViewControl()) { @@ -655,9 +712,11 @@ 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); var mainWindow = mocks.Stub(); @@ -673,7 +732,7 @@ { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; - helper.ClickCancel(); + helper.ClickOk(); }; ChangeSurfaceLine(surfaceLine); @@ -684,8 +743,8 @@ contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); // Then - Assert.IsTrue(calculation.HasOutput); - Assert.IsFalse(calculation.InputParameters.IsEntryAndExitPointInputSynchronized); + Assert.IsFalse(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsEntryAndExitPointInputSynchronized); string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";