Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rc9396d0af18873fda14c7e486decbfca7d4e8b21 -r20415b2886919a103cb4677f56a8f61abbb7aa8a --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision c9396d0af18873fda14c7e486decbfca7d4e8b21) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision 20415b2886919a103cb4677f56a8f61abbb7aa8a) @@ -188,6 +188,7 @@ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().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.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); @@ -239,8 +240,14 @@ var menu = info.ContextMenuStrip(nodeData, assessmentSectionMock, treeViewControl); // Assert - Assert.AreEqual(6, menu.Items.Count); + Assert.AreEqual(7, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.GuiPlugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, RingtoetsCommonFormsResources.Calculate, RingtoetsCommonFormsResources.GuiPlugin_AllDataAvailable_No_failure_mechanism_sections_imported, @@ -298,8 +305,7 @@ new Point2D(0, 0) })); - var assessmentSectionMock = mocks.StrictMock(); - assessmentSectionMock.Expect(asm => asm.HydraulicBoundaryDatabase).Return(null); + var assessmentSectionMock = mocks.Stub(); var calculation = new HeightStructuresCalculation(); var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); @@ -409,13 +415,168 @@ } [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + var assessmentSectionMock = mocks.StrictMock(); + var calculation = new HeightStructuresCalculation(); + + var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + var guiMock = mocks.StrictMock(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.GuiPlugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var guiMock = mocks.StrictMock(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + + var calculation = new HeightStructuresCalculation(); + var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.GuiPlugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var guiMock = mocks.StrictMock(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var calculation = new HeightStructuresCalculation(); + var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + + // 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); + } + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicBoundaryDatabaseSet_ContextMenuItemValidateCalculationEnabled() + { + // Setup + var guiMock = mocks.StrictMock(); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var calculation = new HeightStructuresCalculation(); + var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Validate_ToolTip, + RingtoetsCommonFormsResources.ValidateIcon); + } + mocks.VerifyAll(); + } + + [Test] public void GivenCalculationWithNonExistingFilePath_WhenCalculatingFromContextMenu_ThenOutputClearedLogMessagesAddedObserversNotNotified() { // Given var gui = mocks.DynamicMock(); var mainWindow = mocks.DynamicMock(); var observerMock = mocks.StrictMock(); - var calculateContextMenuItemIndex = 0; var section = new FailureMechanismSection("A", new[] { @@ -435,11 +596,10 @@ Version = "random" }; hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase - }; var calculation = new HeightStructuresCalculation { Output = new ProbabilityAssessmentOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN), @@ -449,7 +609,7 @@ } }; - var calculationContext = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSection); + var calculationContext = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); using (var treeViewControl = new TreeViewControl()) { @@ -470,7 +630,7 @@ }; // When - Action action = () => { contextMenuAdapter.Items[calculateContextMenuItemIndex].PerformClick(); }; + Action action = () => { contextMenuAdapter.Items[contextMenuCalculateIndex].PerformClick(); }; // Then TestHelper.AssertLogMessages(action, messages => @@ -488,6 +648,71 @@ } [Test] + public void GivenCalculationWithNonExistingFilePath_WhenValidatingFromContextMenu_ThenLogMessagesAdded() + { + // Given + var gui = mocks.DynamicMock(); + var observerMock = mocks.StrictMock(); + + var section = new FailureMechanismSection("A", new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(section); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0.0, 1.1); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random" + }; + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var calculation = new HeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + + var calculationContext = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + gui.Expect(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + calculation.Attach(observerMock); + + var contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControl); + + // When + Action action = () => { contextMenuAdapter.Items[contextMenuValidateIndex].PerformClick(); }; + + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.ToArray(); + 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]); + }); + } + mocks.VerifyAll(); + } + + [Test] public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() { // Setup @@ -524,8 +749,9 @@ } - private const int contextMenuCalculateIndex = 0; - private const int contextMenuClearIndex = 1; + private const int contextMenuValidateIndex = 0; + private const int contextMenuCalculateIndex = 1; + private const int contextMenuClearIndex = 2; private class TestHeightStructuresOutput : ProbabilityAssessmentOutput {