Index: Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs
===================================================================
diff -u -r0d3788fdf7aa5b050974f69bcea4f8e71a096d58 -r0324c332753d36bb804a804b9757ef1cd336435f
--- Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 0d3788fdf7aa5b050974f69bcea4f8e71a096d58)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 0324c332753d36bb804a804b9757ef1cd336435f)
@@ -145,12 +145,15 @@
/// The toolTip of the import item.
/// The image of the import item.
/// The created .
- /// Thrown when any parameter is null.
+ /// Thrown when
+ /// is null or only whitespace.
+ /// Thrown when
+ /// or is null.
public ToolStripItem CreateCustomImportItem(string text, string toolTip, Image image)
{
- if (text == null)
+ if(string.IsNullOrWhiteSpace(text))
{
- throw new ArgumentNullException("text");
+ throw new ArgumentException(@"Text should be set.", "text");
}
if (toolTip == null)
{
Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs
===================================================================
diff -u -r0d3788fdf7aa5b050974f69bcea4f8e71a096d58 -r0324c332753d36bb804a804b9757ef1cd336435f
--- Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 0d3788fdf7aa5b050974f69bcea4f8e71a096d58)
+++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 0324c332753d36bb804a804b9757ef1cd336435f)
@@ -325,7 +325,10 @@
}
[Test]
- public void CreateCustomImportItem_TextNull_ThrowArgumentNullException()
+ [TestCase(null)]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void CreateCustomImportItem_TextInvalid_ThrowArgumentException(string text)
{
// Setup
const string toolTip = "Import tooltip";
@@ -346,11 +349,12 @@
nodeData);
// Call
- TestDelegate test = () => contextMenuFactory.CreateCustomImportItem(null, toolTip, image);
+ TestDelegate test = () => contextMenuFactory.CreateCustomImportItem(text, toolTip, image);
// Assert
- var exception = Assert.Throws(test);
+ var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "Text should be set.");
Assert.AreEqual("text", exception.ParamName);
+ mocks.VerifyAll();
}
[Test]
@@ -380,6 +384,7 @@
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("toolTip", exception.ParamName);
+ mocks.VerifyAll();
}
[Test]
@@ -409,6 +414,7 @@
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("image", exception.ParamName);
+ mocks.VerifyAll();
}
[Test]
Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/ContextMenu/CustomItemsOnlyContextMenuBuilderTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.TestUtil.Test/ContextMenu/CustomItemsOnlyContextMenuBuilderTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.TestUtil.Test/ContextMenu/CustomItemsOnlyContextMenuBuilderTest.cs (revision 0324c332753d36bb804a804b9757ef1cd336435f)
@@ -0,0 +1,211 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Drawing;
+using System.Windows.Forms;
+using Core.Common.Gui.ContextMenu;
+using Core.Common.Gui.TestUtil.ContextMenu;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources;
+
+namespace Core.Common.Gui.TestUtil.Test.ContextMenu
+{
+ [TestFixture]
+ public class CustomItemsOnlyContextMenuBuilderTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Assert
+ Assert.IsInstanceOf(builder);
+ }
+
+ [Test]
+ public void AddRenameItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddRenameItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddDeleteItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddDeleteItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddDeleteChildrenItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddDeleteChildrenItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddExpandAllItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddExpandAllItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddCollapseAllItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddCollapseAllItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddOpenItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddOpenItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddExportItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddExportItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddImportItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddImportItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddCustomImportItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddCustomImportItem(null, null, null).Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddPropertiesItem_WhenBuild_StubbedItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddPropertiesItem().Build();
+
+ // Assert
+ AssertStubbedContextMenuItem(result);
+ }
+
+ [Test]
+ public void AddSeparatorItem_WhenBuild_SeparatorItemAddedToContextMenu()
+ {
+ // Setup
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip result = builder.AddSeparator().Build();
+
+ // Assert
+ Assert.IsInstanceOf(result.Items[0]);
+ }
+
+ [Test]
+ public void AddCustomItem_WhenBuild_CustomItemAddedToContextMenu()
+ {
+ // Setup
+ const string text = "custom item";
+ const string toolTip = "tooltip";
+ Bitmap image = CoreCommonGuiResources.Busy_indicator;
+ var customItem = new StrictContextMenuItem(text, toolTip, image, (sender, args) => { });
+
+ var builder = new CustomItemsOnlyContextMenuBuilder();
+
+ // Call
+ ContextMenuStrip menu = builder.AddCustomItem(customItem).Build();
+
+ // Assert
+ TestHelper.AssertContextMenuStripContainsItem(menu, 0, text, toolTip, image);
+ }
+
+ private void AssertStubbedContextMenuItem(ContextMenuStrip menu)
+ {
+ TestHelper.AssertContextMenuStripContainsItem(menu, 0, string.Empty, string.Empty, null);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj
===================================================================
diff -u -rbc4c4000ca4a850b49a88156ca2b919ea690494b -r0324c332753d36bb804a804b9757ef1cd336435f
--- Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision bc4c4000ca4a850b49a88156ca2b919ea690494b)
+++ Core/Common/test/Core.Common.Gui.TestUtil.Test/Core.Common.Gui.TestUtil.Test.csproj (.../Core.Common.Gui.TestUtil.Test.csproj) (revision 0324c332753d36bb804a804b9757ef1cd336435f)
@@ -40,11 +40,14 @@
+
+
Properties\GlobalAssembly.cs
+
Code
@@ -69,6 +72,10 @@
{26214BD0-DAFB-4CFC-8EB2-80C5D53C859E}
Core.Common.Gui.TestUtil
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+