Index: Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs
===================================================================
diff -u -r7f759fbabca9c41e75d229269f1b21581b373b5f -r080a506f538107c3bdcdeb0fdafcc21772a94357
--- Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 7f759fbabca9c41e75d229269f1b21581b373b5f)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 080a506f538107c3bdcdeb0fdafcc21772a94357)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Drawing;
using System.Windows.Forms;
using Core.Common.Gui.Commands;
using Core.Common.Gui.Properties;
@@ -133,16 +134,33 @@
/// The created .
public ToolStripItem CreateImportItem()
{
- bool canImport = importCommandHandler.CanImportOn(dataObject);
- var newItem = new ToolStripMenuItem(Resources.Import)
- {
- ToolTipText = Resources.Import_ToolTip,
- Image = Resources.ImportIcon,
- Enabled = canImport
- };
- newItem.Click += (s, e) => importCommandHandler.ImportOn(dataObject);
+ return CreateImportItem(Resources.Import, Resources.Import_ToolTip, Resources.ImportIcon);
+ }
- return newItem;
+ ///
+ /// Creates a which is bound to the action of importing
+ /// to the data of the given .
+ ///
+ /// The text of the import item.
+ /// The tooltip of the import item.
+ /// The image of the import item.
+ /// The created .
+ /// Thrown when any parameter is null.
+ public ToolStripItem CreateCustomImportItem(string text, string tooltip, Image image)
+ {
+ if (text == null)
+ {
+ throw new ArgumentNullException("text");
+ }
+ if (tooltip == null)
+ {
+ throw new ArgumentNullException("tooltip");
+ }
+ if (image == null)
+ {
+ throw new ArgumentNullException("image");
+ }
+ return CreateImportItem(text, tooltip, image);
}
///
@@ -163,5 +181,19 @@
return newItem;
}
+
+ private ToolStripItem CreateImportItem(string text, string tooltip, Image image)
+ {
+ bool canImport = importCommandHandler.CanImportOn(dataObject);
+ var newItem = new ToolStripMenuItem(text)
+ {
+ ToolTipText = tooltip,
+ Image = image,
+ Enabled = canImport
+ };
+ newItem.Click += (s, e) => importCommandHandler.ImportOn(dataObject);
+
+ return newItem;
+ }
}
}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs
===================================================================
diff -u -rf64dceaa32788bad28dcf09f4a1c3150595f1327 -r080a506f538107c3bdcdeb0fdafcc21772a94357
--- Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision f64dceaa32788bad28dcf09f4a1c3150595f1327)
+++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 080a506f538107c3bdcdeb0fdafcc21772a94357)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Drawing;
using Core.Common.Gui.Commands;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Properties;
@@ -324,8 +325,137 @@
}
[Test]
+ public void CreateCustomImportItem_TextNull_ThrowArgumentNullException()
+ {
+ // Setup
+ const string tooltip = "Import tooltip";
+ Image image = Resources.ImportIcon;
+
+ var commandHandlerMock = mocks.StrictMock();
+ var importCommandHandlerMock = mocks.StrictMock();
+ var exportCommandHandlerMock = mocks.StrictMock();
+ var viewCommandsMock = mocks.StrictMock();
+ var nodeData = new object();
+
+ mocks.ReplayAll();
+
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock,
+ importCommandHandlerMock,
+ exportCommandHandlerMock,
+ viewCommandsMock,
+ nodeData);
+
+ // Call
+ TestDelegate test = () => contextMenuFactory.CreateCustomImportItem(null, tooltip, image);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("text", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateCustomImportItem_TooltipNull_ThrowArgumentNullException()
+ {
+ // Setup
+ const string text = "Import";
+ Image image = Resources.ImportIcon;
+
+ var commandHandlerMock = mocks.StrictMock();
+ var importCommandHandlerMock = mocks.StrictMock();
+ var exportCommandHandlerMock = mocks.StrictMock();
+ var viewCommandsMock = mocks.StrictMock();
+ var nodeData = new object();
+
+ mocks.ReplayAll();
+
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock,
+ importCommandHandlerMock,
+ exportCommandHandlerMock,
+ viewCommandsMock,
+ nodeData);
+
+ // Call
+ TestDelegate test = () => contextMenuFactory.CreateCustomImportItem(text, null, image);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("tooltip", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateCustomImportItem_ImageNull_ThrowArgumentNullException()
+ {
+ // Setup
+ const string text = "Import";
+ const string tooltip = "Import tooltip";
+
+ var commandHandlerMock = mocks.StrictMock();
+ var importCommandHandlerMock = mocks.StrictMock();
+ var exportCommandHandlerMock = mocks.StrictMock();
+ var viewCommandsMock = mocks.StrictMock();
+ var nodeData = new object();
+
+ mocks.ReplayAll();
+
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock,
+ importCommandHandlerMock,
+ exportCommandHandlerMock,
+ viewCommandsMock,
+ nodeData);
+
+ // Call
+ TestDelegate test = () => contextMenuFactory.CreateCustomImportItem(text, tooltip, null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("image", exception.ParamName);
+ }
+
+ [Test]
[TestCase(true)]
[TestCase(false)]
+ public void CreateCustomImportItem_AllDataSet_ItemWithPropertiesSet(bool canImportOn)
+ {
+ // Setup
+ const string text = "Import";
+ const string tooltip = "Import tooltip";
+ Image image = Resources.ImportIcon;
+
+ var commandHandlerMock = mocks.StrictMock();
+ var importCommandHandlerMock = mocks.StrictMock();
+ var exportCommandHandlerMock = mocks.StrictMock();
+ var viewCommandsMock = mocks.StrictMock();
+ var nodeData = new object();
+ importCommandHandlerMock.Expect(ch => ch.CanImportOn(nodeData)).Return(canImportOn);
+ if (canImportOn)
+ {
+ importCommandHandlerMock.Expect(ch => ch.ImportOn(nodeData));
+ }
+
+ mocks.ReplayAll();
+
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock,
+ importCommandHandlerMock,
+ exportCommandHandlerMock,
+ viewCommandsMock,
+ nodeData);
+
+ // Call
+ var item = contextMenuFactory.CreateCustomImportItem(text, tooltip, image);
+ item.PerformClick();
+
+ // Assert
+ Assert.AreEqual(text, item.Text);
+ Assert.AreEqual(tooltip, item.ToolTipText);
+ TestHelper.AssertImagesAreEqual(image, item.Image);
+ Assert.AreEqual(canImportOn, item.Enabled);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
public void CreatePropertiesItem_Always_ItemWithPropertiesSet(bool hasPropertyInfoForNodeData)
{
// Setup