Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicBoundaryDataContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9450cac070c8628735b79d7614109ba6bed6913 -rdad401272a96f4e5e14b1c98dd24e1b3c8047806 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicBoundaryDataContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDataContextTreeNodeInfoTest.cs) (revision a9450cac070c8628735b79d7614109ba6bed6913) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicBoundaryDataContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDataContextTreeNodeInfoTest.cs) (revision dad401272a96f4e5e14b1c98dd24e1b3c8047806) @@ -45,7 +45,7 @@ public class HydraulicBoundaryDataContextTreeNodeInfoTest : NUnitFormTest { private const int contextMenuImportHydraulicBoundaryDatabaseIndex = 0; - private const int contextMenuSelectDifferentFolderIndex = 1; + private const int contextMenuSelectDifferentFolderIndex = 0; private MockRepository mocks; Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest.cs =================================================================== diff -u -ra0766ff5c8f0a6f790161490dac0dc38c489853e -rdad401272a96f4e5e14b1c98dd24e1b3c8047806 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest.cs (.../HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest.cs) (revision a0766ff5c8f0a6f790161490dac0dc38c489853e) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest.cs (.../HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest.cs) (revision dad401272a96f4e5e14b1c98dd24e1b3c8047806) @@ -21,12 +21,20 @@ using System.Drawing; using System.Linq; +using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; +using Core.Gui; +using Core.Gui.Commands; +using Core.Gui.ContextMenu; +using Core.Gui.Forms.Main; +using Core.Gui.Plugin; using NUnit.Extensions.Forms; using NUnit.Framework; +using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Plugin.TestUtil; using Riskeer.Integration.Data; using Riskeer.Integration.Forms.PresentationObjects; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -36,6 +44,8 @@ [TestFixture] public class HydraulicLocationConfigurationDatabaseContextTreeNodeInfoTest : NUnitFormTest { + private readonly int contextMenuImportHydraulicLocationConfigurationDatabaseIndex = 0; + [Test] public void Initialized_Always_ExpectedPropertiesSet() { @@ -48,7 +58,7 @@ Assert.IsNotNull(info.Text); Assert.IsNull(info.ForeColor); Assert.IsNotNull(info.Image); - Assert.IsNull(info.ContextMenuStrip); + Assert.IsNotNull(info.ContextMenuStrip); Assert.IsNotNull(info.EnsureVisibleOnCreate); Assert.IsNull(info.ExpandOnCreate); Assert.IsNull(info.ChildNodeObjects); @@ -126,6 +136,101 @@ } } + [Test] + public void ContextMenuStrip_WithContext_CallsContextMenuBuilderMethods() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var context = new HydraulicLocationConfigurationDatabaseContext(assessmentSection.HydraulicBoundaryData, assessmentSection); + + var mocks = new MockRepository(); + var menuBuilder = mocks.StrictMock(); + + using (mocks.Ordered()) + { + menuBuilder.Expect(mb => mb.AddImportItem(null, null, null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.Build()).Return(null); + } + + using (var treeViewControl = new TreeViewControl()) + { + IGui gui = StubFactory.CreateGuiStub(mocks); + gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(context, null, treeViewControl); + } + } + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_WithContext_AddImportItem() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var context = new HydraulicLocationConfigurationDatabaseContext(assessmentSection.HydraulicBoundaryData, assessmentSection); + + var mocks = new MockRepository(); + var applicationFeatureCommands = mocks.Stub(); + var importCommandHandler = mocks.Stub(); + importCommandHandler.Stub(ich => ich.GetSupportedImportInfos(null)).IgnoreArguments().Return(new[] + { + new ImportInfo() + }); + var exportCommandHandler = mocks.Stub(); + var updateCommandHandler = mocks.Stub(); + var viewCommands = mocks.Stub(); + + using (var treeViewControl = new TreeViewControl()) + { + var builder = new ContextMenuBuilder(applicationFeatureCommands, + importCommandHandler, + exportCommandHandler, + updateCommandHandler, + viewCommands, + context, + treeViewControl); + + IGui gui = StubFactory.CreateGuiStub(mocks); + gui.Stub(g => g.Get(context, treeViewControl)).Return(builder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(context, assessmentSection, treeViewControl)) + { + Assert.AreEqual(3, contextMenuStrip.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(contextMenuStrip, contextMenuImportHydraulicLocationConfigurationDatabaseIndex, + "&Selecteer ander HLCD bestand...", + "Selecteer een ander HLCD bestand.", + RiskeerCommonFormsResources.DatabaseIcon); + } + } + } + + // Assert + mocks.VerifyAll(); + } + private static TreeNodeInfo GetInfo(RiskeerPlugin plugin) { return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HydraulicLocationConfigurationDatabaseContext));