Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rf7abd6ab0bf0f053056fb45ad655c3bb17fab3f6 -r19d2c2e6cd9b096eb1a561d48c8e38b80ed8cac2 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision f7abd6ab0bf0f053056fb45ad655c3bb17fab3f6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision 19d2c2e6cd9b096eb1a561d48c8e38b80ed8cac2) @@ -20,14 +20,15 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Drawing; 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.TreeView; using Core.Common.Gui; -using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.TestUtil.ContextMenu; @@ -104,7 +105,7 @@ mocks.ReplayAll(); // Call - var image = info.Image(null); + Image image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculationIcon, image); @@ -137,7 +138,7 @@ assessmentSection); // Call - var children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); + object[] children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); @@ -172,7 +173,7 @@ Assert.IsFalse(pipingCalculationContext.WrappedData.HasOutput); // Call - var children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); + object[] children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); @@ -475,21 +476,9 @@ 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, - EntryPointL = (RoundedDouble) 0, - ExitPointL = (RoundedDouble) 1 - } - }; + RingtoetsPipingSurfaceLine surfaceLine; + PipingCalculationScenario calculation; + CreateCalculationWithSurfaceLine(out calculation, out surfaceLine); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); @@ -510,25 +499,14 @@ var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When - surfaceLine.SetGeometry(new[] - { - new Point3D(0, 0, 0), - new Point3D(1, 0, 2), - new Point3D(2, 0, 3), - new Point3D(3, 0, 0), - new Point3D(4, 0, 2), - new Point3D(5, 0, 3) - }); - surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); - surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + UpdateSurfaceLine(surfaceLine); contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); @@ -550,22 +528,10 @@ 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, - EntryPointL = (RoundedDouble) 0, - ExitPointL = (RoundedDouble) 1 - }, - Output = new TestPipingOutput() - }; + RingtoetsPipingSurfaceLine surfaceLine; + PipingCalculationScenario calculation; + CreateCalculationWithSurfaceLine(out calculation, out surfaceLine); + calculation.Output = new TestPipingOutput(); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); @@ -587,7 +553,6 @@ var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -603,17 +568,7 @@ using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When - surfaceLine.SetGeometry(new[] - { - new Point3D(0, 0, 0), - new Point3D(1, 0, 2), - new Point3D(2, 0, 3), - new Point3D(3, 0, 0), - new Point3D(4, 0, 2), - new Point3D(5, 0, 3) - }); - surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); - surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + UpdateSurfaceLine(surfaceLine); contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); @@ -675,7 +630,6 @@ var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -691,17 +645,7 @@ using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When - surfaceLine.SetGeometry(new[] - { - new Point3D(0, 0, 0), - new Point3D(1, 0, 2), - new Point3D(2, 0, 3), - new Point3D(3, 0, 0), - new Point3D(4, 0, 2), - new Point3D(5, 0, 3) - }); - surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); - surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + UpdateSurfaceLine(surfaceLine); contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); @@ -728,22 +672,10 @@ 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, - EntryPointL = (RoundedDouble) 0, - ExitPointL = (RoundedDouble) 1 - }, - Output = new TestPipingOutput() - }; + RingtoetsPipingSurfaceLine surfaceLine; + PipingCalculationScenario calculation; + CreateCalculationWithSurfaceLine(out calculation, out surfaceLine); + calculation.Output = new TestPipingOutput(); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); @@ -763,7 +695,6 @@ var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -779,17 +710,7 @@ using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When - surfaceLine.SetGeometry(new[] - { - new Point3D(0, 0, 0), - new Point3D(1, 0, 2), - new Point3D(2, 0, 3), - new Point3D(3, 0, 0), - new Point3D(4, 0, 2), - new Point3D(5, 0, 3) - }); - surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); - surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + UpdateSurfaceLine(surfaceLine); contextMenuStrip.Items[contextMenuUpdateEntryAndExitPointIndex].PerformClick(); @@ -862,8 +783,8 @@ var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); - var pipingFailureMechanism = TestPipingFailureMechanism.GetFailureMechanismWithSurfaceLinesAndStochasticSoilModels(); - var surfaceLines = pipingFailureMechanism.SurfaceLines.ToArray(); + TestPipingFailureMechanism pipingFailureMechanism = TestPipingFailureMechanism.GetFailureMechanismWithSurfaceLinesAndStochasticSoilModels(); + RingtoetsPipingSurfaceLine[] surfaceLines = pipingFailureMechanism.SurfaceLines.ToArray(); var elementToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput()) { @@ -896,7 +817,7 @@ // Precondition Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); Assert.AreEqual(2, group.Children.Count); - var sectionResults = pipingFailureMechanism.SectionResults.ToArray(); + PipingFailureMechanismSectionResult[] sectionResults = pipingFailureMechanism.SectionResults.ToArray(); CollectionAssert.Contains(sectionResults[0].GetCalculationScenarios(pipingFailureMechanism.Calculations.OfType()), elementToBeRemoved); // Call @@ -957,10 +878,10 @@ var expectedValidationMessageCount = 5; TestHelper.AssertLogMessages(action, messages => { - var msgs = messages.GetEnumerator(); + IEnumerator msgs = messages.GetEnumerator(); Assert.IsTrue(msgs.MoveNext()); StringAssert.StartsWith("Validatie van 'Nieuwe berekening' gestart om: ", msgs.Current); - for (int i = 0; i < expectedValidationMessageCount; i++) + for (var i = 0; i < expectedValidationMessageCount; i++) { Assert.IsTrue(msgs.MoveNext()); StringAssert.StartsWith("Validatie mislukt: ", msgs.Current); @@ -1010,7 +931,7 @@ // Then var expectedValidationMessageCount = 5; var expectedStatusMessageCount = 2; - var expectedLogMessageCount = expectedValidationMessageCount + expectedStatusMessageCount; + int expectedLogMessageCount = expectedValidationMessageCount + expectedStatusMessageCount; TestHelper.AssertLogMessagesCount(action, expectedLogMessageCount); } } @@ -1057,15 +978,15 @@ // Expect an activity dialog which is automatically closed }; - using (var contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, null, treeViewControl)) + using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, null, treeViewControl)) { // When Action action = () => contextMenuAdapter.Items[contextMenuCalculateIndex].PerformClick(); // Then TestHelper.AssertLogMessages(action, messages => { - var msgs = messages.GetEnumerator(); + IEnumerator msgs = messages.GetEnumerator(); Assert.IsTrue(msgs.MoveNext()); StringAssert.StartsWith("Validatie van 'Nieuwe berekening' gestart om: ", msgs.Current); Assert.IsTrue(msgs.MoveNext()); @@ -1146,6 +1067,40 @@ } } + private static void UpdateSurfaceLine(RingtoetsPipingSurfaceLine surfaceLine) + { + surfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(1, 0, 2), + new Point3D(2, 0, 3), + new Point3D(3, 0, 0), + new Point3D(4, 0, 2), + new Point3D(5, 0, 3) + }); + surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); + surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); + } + + private void CreateCalculationWithSurfaceLine(out PipingCalculationScenario calculation, out RingtoetsPipingSurfaceLine surfaceLine) + { + surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + EntryPointL = (RoundedDouble) 0, + ExitPointL = (RoundedDouble) 1 + } + }; + } + public override void TearDown() { plugin.Dispose();