Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -rff8a088931e6af2e46f6f4f09b633bcdd0b84ecd --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision ff8a088931e6af2e46f6f4f09b633bcdd0b84ecd) @@ -228,28 +228,29 @@ plugin.Gui = guiMock; // Call - var menu = info.ContextMenuStrip(nodeData, assessmentSectionMock, treeViewControl); + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSectionMock, treeViewControl)) + { + // Assert + Assert.AreEqual(6, menu.Items.Count); - // Assert - Assert.AreEqual(6, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, - RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, - RingtoetsCommonFormsResources.ValidateIcon, - false); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, - RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, - RingtoetsCommonFormsResources.CalculateIcon, - false); - - TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, - RingtoetsCommonFormsResources.Clear_output, - RingtoetsCommonFormsResources.ClearOutput_No_output_to_clear, - RingtoetsCommonFormsResources.ClearIcon, - false); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, + RingtoetsCommonFormsResources.Clear_output, + RingtoetsCommonFormsResources.ClearOutput_No_output_to_clear, + RingtoetsCommonFormsResources.ClearIcon, + false); + } } } @@ -273,14 +274,15 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, - RingtoetsCommonFormsResources.CalculateIcon, - false); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); + } } } @@ -310,14 +312,15 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, - RingtoetsCommonFormsResources.CalculateIcon, - false); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); + } } } @@ -348,15 +351,16 @@ plugin.Gui = guiMock; // Call - ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateIndex]; - // Assert - ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateIndex]; - - Assert.AreEqual(RingtoetsCommonFormsResources.Calculate, contextMenuItem.Text); - StringAssert.Contains(string.Format(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateIcon, contextMenuItem.Image); - Assert.IsFalse(contextMenuItem.Enabled); + Assert.AreEqual(RingtoetsCommonFormsResources.Calculate, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } } } @@ -395,13 +399,14 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, - RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Calculate_ToolTip, - RingtoetsCommonFormsResources.CalculateIcon); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Calculate_ToolTip, + RingtoetsCommonFormsResources.CalculateIcon); + } } } @@ -425,14 +430,15 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, - RingtoetsCommonFormsResources.ValidateIcon, - false); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } } } @@ -462,14 +468,15 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, - RingtoetsCommonFormsResources.ValidateIcon, - false); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } } } @@ -500,15 +507,16 @@ plugin.Gui = guiMock; // Call - ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateIndex]; - // Assert - ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateIndex]; - - Assert.AreEqual(RingtoetsCommonFormsResources.Validate, contextMenuItem.Text); - StringAssert.Contains(string.Format(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateIcon, contextMenuItem.Image); - Assert.IsFalse(contextMenuItem.Enabled); + Assert.AreEqual(RingtoetsCommonFormsResources.Validate, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } } } @@ -547,13 +555,14 @@ plugin.Gui = guiMock; // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); - - // Assert - TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, - RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Validate_ToolTip, - RingtoetsCommonFormsResources.ValidateIcon); + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Validate_ToolTip, + RingtoetsCommonFormsResources.ValidateIcon); + } } } @@ -610,31 +619,32 @@ calculation.Attach(observerMock); - var contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControl); - DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; - // When - Action action = () => { contextMenuAdapter.Items[contextMenuCalculateIndex].PerformClick(); }; - - // Then - TestHelper.AssertLogMessages(action, messages => + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { - var msgs = messages.ToArray(); - Assert.AreEqual(7, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]); - StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[4]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); - StringAssert.StartsWith(string.Format("Uitvoeren van '{0}' is mislukt.", calculation.Name), msgs[6]); - }); + // When + Action action = () => contextMenuStrip.Items[contextMenuCalculateIndex].PerformClick(); - Assert.IsNull(calculation.Output); + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(7, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]); + StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[4]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); + StringAssert.StartsWith(string.Format("Uitvoeren van '{0}' is mislukt.", calculation.Name), msgs[6]); + }); + + Assert.IsNull(calculation.Output); + } } } @@ -687,19 +697,20 @@ calculation.Attach(observerMock); - var contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControl); - - // When - Action action = () => { contextMenuAdapter.Items[contextMenuValidateIndex].PerformClick(); }; - - // Then - TestHelper.AssertLogMessages(action, messages => + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { - var msgs = messages.ToArray(); - Assert.AreEqual(2, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - }); + // When + Action action = () => contextMenuStrip.Items[contextMenuValidateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + }); + } } }