Index: Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs
===================================================================
diff -u -r4fde87e9b64c21a70b06ff295fd34cc1932fe72a -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision 4fde87e9b64c21a70b06ff295fd34cc1932fe72a)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -9,7 +9,7 @@
/// This class represents a builder which can be used to create a context menu, which's items require information
/// on the in order to render or perform actions.
///
- public class ContextMenuBuilder
+ public class ContextMenuBuilder : IContextMenuBuilder
{
private readonly GuiContextMenuItemFactory guiItemsFactory;
private readonly TreeViewContextMenuItemFactory treeViewItemsFactory;
@@ -23,110 +23,68 @@
/// to the items of the . If null, this builder will not render items which
/// require this type of information.
/// The for which to create a .
- /// Thrown when is null.
+ /// Thrown when either:
+ ///
+ /// - is null
+ /// - is null
+ ///
public ContextMenuBuilder(IGuiCommandHandler commandHandler, ITreeNode treeNode)
{
if (commandHandler != null)
{
- guiItemsFactory = new GuiContextMenuItemFactory(commandHandler);
+ guiItemsFactory = new GuiContextMenuItemFactory(commandHandler, treeNode);
}
treeViewItemsFactory = new TreeViewContextMenuItemFactory(treeNode);
contextMenu = new ContextMenuStrip();
}
- ///
- /// Adds an item to the , which deletes the .
- ///
- /// The itself, so that operations can be easily chained.
- public ContextMenuBuilder AddDeleteItem()
+ public IContextMenuBuilder AddDeleteItem()
{
AddItem(treeViewItemsFactory.CreateDeleteItem());
return this;
}
- ///
- /// Adds an item to the , which expands the .
- ///
- /// The itself, so that operations can be easily chained.
- public ContextMenuBuilder AddExpandAllItem()
+ public IContextMenuBuilder AddExpandAllItem()
{
AddItem(treeViewItemsFactory.CreateExpandAllItem());
return this;
}
- ///
- /// Adds an item to the , which collapses the .
- ///
- /// The itself, so that operations can be easily chained.
- public ContextMenuBuilder AddCollapseAllItem()
+ public IContextMenuBuilder AddCollapseAllItem()
{
AddItem(treeViewItemsFactory.CreateCollapseAllItem());
return this;
}
- ///
- /// Adds an item to the , which opens a view for the data of the .
- ///
- /// The itself, so that operations can be easily chained.
- /// If the was not passed on construction, this method will not add an item.
- public ContextMenuBuilder AddOpenItem()
+ public IContextMenuBuilder AddOpenItem()
{
- if (guiItemsFactory != null)
- {
- AddItem(guiItemsFactory.CreateOpenItem());
- }
+ CheckGuiItemsFactory();
+ AddItem(guiItemsFactory.CreateOpenItem());
return this;
}
- ///
- /// Adds an item to the , which exports the data of the .
- ///
- /// The itself, so that operations can be easily chained.
- /// If the was not passed on construction, this method will not add an item.
- public ContextMenuBuilder AddExportItem()
+ public IContextMenuBuilder AddExportItem()
{
- if (guiItemsFactory != null)
- {
- AddItem(guiItemsFactory.CreateExportItem());
- }
+ CheckGuiItemsFactory();
+ AddItem(guiItemsFactory.CreateExportItem());
return this;
}
- ///
- /// Adds an item to the , which imports the data of the .
- ///
- /// The itself, so that operations can be easily chained.
- /// If the was not passed on construction, this method will not add an item.
- public ContextMenuBuilder AddImportItem()
+ public IContextMenuBuilder AddImportItem()
{
- if (guiItemsFactory != null)
- {
- AddItem(guiItemsFactory.CreateImportItem());
- }
+ CheckGuiItemsFactory();
+ AddItem(guiItemsFactory.CreateImportItem());
return this;
}
- ///
- /// Adds an item to the , which shows properties of the data of the .
- ///
- /// The itself, so that operations can be easily chained.
- /// If the was not passed on construction, this method will not add an item.
- public ContextMenuBuilder AddPropertiesItem()
+ public IContextMenuBuilder AddPropertiesItem()
{
- if (guiItemsFactory != null)
- {
- AddItem(guiItemsFactory.CreatePropertiesItem());
- }
+ CheckGuiItemsFactory();
+ AddItem(guiItemsFactory.CreatePropertiesItem());
return this;
}
- ///
- /// Adds a to the . A
- /// is only added if the last item that was added to the exists and is not a
- /// .
- ///
- /// The itself, so that operations can be easily chained.
- public ContextMenuBuilder AddSeparator()
+ public IContextMenuBuilder AddSeparator()
{
if (MayAddSeparator())
{
@@ -135,27 +93,33 @@
return this;
}
- ///
- /// Adds a custom item to the .
- ///
- /// The custom to add to the .
- /// The itself, so that operations can be easily chained.
- public ContextMenuBuilder AddCustomItem(StrictContextMenuItem item)
+ public IContextMenuBuilder AddCustomItem(StrictContextMenuItem item)
{
AddItem(item);
return this;
}
- ///
- /// Obtain the , which has been constructed by using the other methods of
- /// .
- ///
- /// The constructed .
public ContextMenuStrip Build()
{
+ if (contextMenu.Items.Count > 0)
+ {
+ var lastIndex = contextMenu.Items.Count - 1;
+ if (contextMenu.Items[lastIndex] is ToolStripSeparator)
+ {
+ contextMenu.Items.RemoveAt(lastIndex);
+ }
+ }
return contextMenu;
}
+ private void CheckGuiItemsFactory()
+ {
+ if (guiItemsFactory == null)
+ {
+ throw new InvalidOperationException(Resources.GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui);
+ }
+ }
+
private bool MayAddSeparator()
{
if (contextMenu.Items.Count == 0)
Index: Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs
===================================================================
diff -u -r5bdfe106fefb36f7e677da7e75afec1eba7eedd3 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 5bdfe106fefb36f7e677da7e75afec1eba7eedd3)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -13,6 +13,7 @@
internal class GuiContextMenuItemFactory
{
private readonly IGuiCommandHandler commandHandler;
+ private readonly ITreeNode treeNode;
///
/// Creates a new instance of , which uses the
@@ -21,13 +22,18 @@
/// The which contains information for creating the
/// .
/// Thrown when is null.
- public GuiContextMenuItemFactory(IGuiCommandHandler commandHandler)
+ public GuiContextMenuItemFactory(IGuiCommandHandler commandHandler, ITreeNode treeNode)
{
if (commandHandler == null)
{
throw new ArgumentNullException("commandHandler", Resources.GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui);
}
+ if (treeNode == null)
+ {
+ throw new ArgumentNullException("treeNode", Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node);
+ }
this.commandHandler = commandHandler;
+ this.treeNode = treeNode;
}
///
@@ -37,14 +43,14 @@
/// The created .
public ToolStripItem CreateOpenItem()
{
- bool canOpenView = commandHandler.CanOpenDefaultViewForSelection();
+ bool canOpenView = commandHandler.CanOpenDefaultViewFor(treeNode.Tag);
var newItem = new ToolStripMenuItem(Resources.Open)
{
ToolTipText = Resources.Open_ToolTip,
Image = Resources.OpenIcon,
Enabled = canOpenView
};
- newItem.Click += (s, e) => commandHandler.OpenDefaultViewForSelection();
+ newItem.Click += (s, e) => commandHandler.OpenView(treeNode.Tag);
return newItem;
}
@@ -56,14 +62,14 @@
/// The created .
public ToolStripItem CreateExportItem()
{
- bool canExport = commandHandler.CanExportFromGuiSelection();
+ bool canExport = commandHandler.CanExportFrom(treeNode.Tag);
var newItem = new ToolStripMenuItem(Resources.Export)
{
ToolTipText = Resources.Export_ToolTip,
Image = Resources.ExportIcon,
Enabled = canExport
};
- newItem.Click += (s, e) => commandHandler.ExportSelectedItem();
+ newItem.Click += (s, e) => commandHandler.ExportFrom(treeNode.Tag);
return newItem;
}
@@ -75,14 +81,14 @@
/// The created .
public ToolStripItem CreateImportItem()
{
- bool canImport = commandHandler.CanImportToGuiSelection();
+ bool canImport = commandHandler.CanImportOn(treeNode.Tag);
var newItem = new ToolStripMenuItem(Resources.Import)
{
ToolTipText = Resources.Import_ToolTip,
Image = Resources.ImportIcon,
Enabled = canImport
};
- newItem.Click += (s,e) => commandHandler.ImportToGuiSelection();
+ newItem.Click += (s, e) => commandHandler.ImportOn(treeNode.Tag);
return newItem;
}
@@ -94,14 +100,14 @@
/// The created .
public ToolStripItem CreatePropertiesItem()
{
- bool canShowProperties = commandHandler.CanShowPropertiesForGuiSelection();
+ bool canShowProperties = commandHandler.CanShowPropertiesFor(treeNode.Tag);
var newItem = new ToolStripMenuItem(Resources.Properties)
{
ToolTipText = Resources.Properties_ToolTip,
Image = Resources.PropertiesIcon,
Enabled = canShowProperties
};
- newItem.Click += (s, e) => commandHandler.ShowProperties();
+ newItem.Click += (s, e) => commandHandler.ShowPropertiesFor(treeNode.Tag);
return newItem;
}
Index: Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs (revision 0)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -0,0 +1,76 @@
+using System;
+using System.Windows.Forms;
+using Core.Common.Controls;
+
+namespace Core.Common.Gui.ContextMenu
+{
+ public interface IContextMenuBuilder {
+ ///
+ /// Adds an item to the , which deletes the .
+ ///
+ /// The itself.
+ IContextMenuBuilder AddDeleteItem();
+
+ ///
+ /// Adds an item to the , which expands the .
+ ///
+ /// The itself.
+ IContextMenuBuilder AddExpandAllItem();
+
+ ///
+ /// Adds an item to the , which collapses the .
+ ///
+ /// The itself.
+ IContextMenuBuilder AddCollapseAllItem();
+
+ ///
+ /// Adds an item to the , which opens a view for the data of the .
+ ///
+ /// The itself.
+ /// Thrown when the was not passed on construction.
+ IContextMenuBuilder AddOpenItem();
+
+ ///
+ /// Adds an item to the , which exports the data of the .
+ ///
+ /// The itself.
+ /// Thrown when the was not passed on construction.
+ IContextMenuBuilder AddExportItem();
+
+ ///
+ /// Adds an item to the , which imports the data of the .
+ ///
+ /// The itself.
+ /// Thrown when the was not passed on construction.
+ IContextMenuBuilder AddImportItem();
+
+ ///
+ /// Adds an item to the , which shows properties of the data of the .
+ ///
+ /// The itself.
+ /// Thrown when the was not passed on construction.
+ IContextMenuBuilder AddPropertiesItem();
+
+ ///
+ /// Adds a to the . A
+ /// is only added if the last item that was added to the exists and is not a
+ /// .
+ ///
+ /// The itself.
+ IContextMenuBuilder AddSeparator();
+
+ ///
+ /// Adds a custom item to the .
+ ///
+ /// The custom to add to the .
+ /// The itself.
+ IContextMenuBuilder AddCustomItem(StrictContextMenuItem item);
+
+ ///
+ /// Obtain the , which has been constructed by using the other methods of
+ /// .
+ ///
+ /// The constructed .
+ ContextMenuStrip Build();
+ }
+}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/ContextMenu/StrictContextMenuItem.cs
===================================================================
diff -u -reb7f8fe1e85f00faf16a1cddef014728d60a2b19 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/ContextMenu/StrictContextMenuItem.cs (.../StrictContextMenuItem.cs) (revision eb7f8fe1e85f00faf16a1cddef014728d60a2b19)
+++ Core/Common/src/Core.Common.Gui/ContextMenu/StrictContextMenuItem.cs (.../StrictContextMenuItem.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -21,7 +21,7 @@
/// The text of the .
/// The tooltip of the .
/// The icon used for the .
- /// The handler for a mouse click on the
+ /// The handler for a mouse click on the created
/// .
public StrictContextMenuItem(string text, string toolTip, Image image, EventHandler clickHandler)
{
Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj
===================================================================
diff -u -r95837098c8fbc25212797c64431f6f16496814b3 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 95837098c8fbc25212797c64431f6f16496814b3)
+++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -119,6 +119,7 @@
+
Index: Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs
===================================================================
diff -u -rd1e069321cba9d3b92f873fdd18e393a20659542 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision d1e069321cba9d3b92f873fdd18e393a20659542)
+++ Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -127,22 +127,23 @@
return gui.DocumentViews.ActiveView != null ? gui.DocumentViews.ActiveView.Data : null;
}
- public void ShowProperties()
+ public void ShowPropertiesFor(object obj)
{
((MainWindow) gui.MainWindow).InitPropertiesWindowAndActivate();
+ gui.Selection = obj;
}
- public bool CanImportToGuiSelection()
+ public bool CanImportOn(object obj)
{
return gui.ApplicationCore.GetSupportedFileImporters(gui.Selection).Any();
}
- public bool CanExportFromGuiSelection()
+ public bool CanExportFrom(object obj)
{
return gui.ApplicationCore.GetSupportedFileExporters(gui.Selection).Any();
}
- public bool CanShowPropertiesForGuiSelection()
+ public bool CanShowPropertiesFor(object obj)
{
return PropertyResolver.GetObjectProperties(gui.Plugins.SelectMany(p => p.GetPropertyInfos()).ToList(), gui.Selection) != null;
}
@@ -166,18 +167,6 @@
}
}
- public void ImportToGuiSelection()
- {
- try
- {
- guiImportHandler.ImportDataTo(gui.Selection);
- }
- catch (Exception)
- {
- Log.ErrorFormat(Resources.GuiCommandHandler_ImportOn_Unable_to_import_on_0_, gui.Selection);
- }
- }
-
public bool CanOpenSelectViewDialog()
{
return gui.Selection != null && gui.DocumentViewsResolver.GetViewInfosFor(gui.Selection).Count() > 1;
@@ -188,16 +177,11 @@
gui.DocumentViewsResolver.OpenViewForData(gui.Selection, null, true);
}
- public bool CanOpenDefaultViewForSelection()
+ public bool CanOpenDefaultViewFor(object obj)
{
- return gui.DocumentViewsResolver.GetDefaultViewType(gui.Selection) != null;
+ return gui.DocumentViewsResolver.GetDefaultViewType(obj) != null;
}
- public void OpenDefaultViewForSelection()
- {
- gui.DocumentViewsResolver.OpenViewForData(gui.Selection);
- }
-
public void OpenView(object dataObject, Type viewType = null)
{
gui.DocumentViewsResolver.OpenViewForData(dataObject, viewType);
@@ -265,17 +249,6 @@
}
}
- public void ExportSelectedItem()
- {
- var selectedObject = gui.Selection;
- if (selectedObject == null)
- {
- return;
- }
-
- guiExportHandler.ExportFrom(selectedObject);
- }
-
public void ExportFrom(object data, IFileExporter exporter = null)
{
if (exporter == null)
Index: Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs
===================================================================
diff -u -ra80efa8773c3efec54ba44940945b03bc3f3ff7e -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs (.../IContextMenuBuilderProvider.cs) (revision a80efa8773c3efec54ba44940945b03bc3f3ff7e)
+++ Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs (.../IContextMenuBuilderProvider.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -17,6 +17,6 @@
/// create a for.
/// The which can be used to create a
/// for .
- ContextMenuBuilder Get(ITreeNode treeNode);
+ IContextMenuBuilder Get(ITreeNode treeNode);
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/IGuiCommandHandler.cs
===================================================================
diff -u -r1f79b34c12554e2b9878f6296168d18232cc9852 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/IGuiCommandHandler.cs (.../IGuiCommandHandler.cs) (revision 1f79b34c12554e2b9878f6296168d18232cc9852)
+++ Core/Common/src/Core.Common.Gui/IGuiCommandHandler.cs (.../IGuiCommandHandler.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -51,11 +51,6 @@
///
void OpenSelectViewDialog();
- ///
- /// Opens the default view for the current selection
- ///
- void OpenDefaultViewForSelection();
-
void OpenViewForSelection(Type viewType = null);
void OpenView(object dataObject, Type viewType = null);
@@ -74,8 +69,9 @@
///
///
- /// true if there is a default vioew for the current selection
- bool CanOpenDefaultViewForSelection();
+ ///
+ /// true if there is a default view for the current selection
+ bool CanOpenDefaultViewFor(object obj);
///
///
@@ -84,31 +80,30 @@
void AddItemToProject(object item);
- void ExportSelectedItem();
-
///
/// Activates the propertyGrid toolbox
///
- void ShowProperties();
+ ///
+ void ShowPropertiesFor(object obj);
- // TODO: move to import plugin
- void ImportToGuiSelection();
-
///
/// Indicates if there are importers for the current Gui.Selection
///
- bool CanImportToGuiSelection();
+ ///
+ bool CanImportOn(object obj);
///
/// Indicates if there are exporters for the current Gui.Selection
///
- bool CanExportFromGuiSelection();
+ ///
+ bool CanExportFrom(object obj);
///
/// Indicates if there is a property view object for the current .
///
+ ///
/// true if a property view is defined, false otherwise.
- bool CanShowPropertiesForGuiSelection();
+ bool CanShowPropertiesFor(object obj);
object GetDataOfActiveView();
Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs
===================================================================
diff -u -r1d61ec19c4b5bf22c714e19e76103befe0a93553 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1d61ec19c4b5bf22c714e19e76103befe0a93553)
+++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -1178,7 +1178,7 @@
}
///
- /// Looks up a localized string similar to Kan geen GUI-afhankelijk element in het contextmenu creëren zonder een GUI..
+ /// Looks up a localized string similar to Kan geen 'GuiCommandHandler'-afhankelijk element in het contextmenu creëren zonder een 'GuiCommandHandler'..
///
public static string GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui {
get {
Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx
===================================================================
diff -u -r1d61ec19c4b5bf22c714e19e76103befe0a93553 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 1d61ec19c4b5bf22c714e19e76103befe0a93553)
+++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -861,7 +861,7 @@
Kan geen contextmenu opbouwen voor een lege knoop.
- Kan geen GUI-afhankelijk element in het contextmenu creëren zonder een GUI.
+ Kan geen 'GuiCommandHandler'-afhankelijk element in het contextmenu creëren zonder een 'GuiCommandHandler'.
Kan geen element in het contextmenu creëren zonder dat de knoop bekend is.
Index: Core/Common/src/Core.Common.Gui/RingtoetsGui.cs
===================================================================
diff -u -r1f79b34c12554e2b9878f6296168d18232cc9852 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 1f79b34c12554e2b9878f6296168d18232cc9852)
+++ Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -253,7 +253,7 @@
}
}
- public ContextMenuBuilder Get(ITreeNode treeNode)
+ public IContextMenuBuilder Get(ITreeNode treeNode)
{
return new ContextMenuBuilder(CommandHandler, treeNode);
}
Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs
===================================================================
diff -u -r8a40ed604cff5c3d15f997d51e81002ae160487e -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs (.../ContextMenuBuilderTest.cs) (revision 8a40ed604cff5c3d15f997d51e81002ae160487e)
+++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs (.../ContextMenuBuilderTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -138,17 +138,16 @@
}
[Test]
- public void AddOpenItem_WithoutGuiWhenBuild_ContextMenuEmpty()
+ public void AddOpenItem_WithoutGuiWhenBuild_InvalidOperationException()
{
// Setup
var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
// Call
- var result = builder.AddOpenItem().Build();
+ TestDelegate test = () => builder.AddOpenItem().Build();
// Assert
- Assert.IsInstanceOf(result);
- Assert.IsEmpty(result.Items);
+ Assert.Throws(test);
}
[Test]
@@ -158,7 +157,7 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanOpenDefaultViewForSelection()).Return(enabled);
+ commandHandlerMock.Expect(ch => ch.CanOpenDefaultViewFor(null)).IgnoreArguments().Return(enabled);
var builder = new ContextMenuBuilder(commandHandlerMock, MockRepository.GenerateMock());
mocks.ReplayAll();
@@ -182,11 +181,10 @@
var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
// Call
- var result = builder.AddExportItem().Build();
+ TestDelegate test = () => builder.AddExportItem().Build();
// Assert
- Assert.IsInstanceOf(result);
- Assert.IsEmpty(result.Items);
+ Assert.Throws(test);
}
[Test]
@@ -196,7 +194,7 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanExportFromGuiSelection()).Return(enabled);
+ commandHandlerMock.Expect(ch => ch.CanExportFrom(null)).IgnoreArguments().Return(enabled);
var builder = new ContextMenuBuilder(commandHandlerMock, MockRepository.GenerateMock());
mocks.ReplayAll();
@@ -220,11 +218,10 @@
var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
// Call
- var result = builder.AddImportItem().Build();
+ TestDelegate test = () => builder.AddImportItem().Build();
// Assert
- Assert.IsInstanceOf(result);
- Assert.IsEmpty(result.Items);
+ Assert.Throws(test);
}
[Test]
@@ -234,7 +231,7 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanImportToGuiSelection()).Return(enabled);
+ commandHandlerMock.Expect(ch => ch.CanImportOn(null)).IgnoreArguments().Return(enabled);
var builder = new ContextMenuBuilder(commandHandlerMock, MockRepository.GenerateMock());
mocks.ReplayAll();
@@ -258,11 +255,10 @@
var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
// Call
- var result = builder.AddPropertiesItem().Build();
+ TestDelegate test = () => builder.AddPropertiesItem().Build();
// Assert
- Assert.IsInstanceOf(result);
- Assert.IsEmpty(result.Items);
+ Assert.Throws(test);
}
[Test]
@@ -272,7 +268,7 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanShowPropertiesForGuiSelection()).Return(enabled);
+ commandHandlerMock.Expect(ch => ch.CanShowPropertiesFor(null)).IgnoreArguments().Return(enabled);
var builder = new ContextMenuBuilder(commandHandlerMock, MockRepository.GenerateMock());
mocks.ReplayAll();
@@ -334,7 +330,7 @@
}
[Test]
- public void AddSeparator_ItemAddedWhenBuild_SeparatorAdded()
+ public void AddSeparator_ItemAddedWhenBuild_SeparatorNotAdded()
{
// Setup
var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
@@ -346,8 +342,27 @@
// Assert
Assert.IsInstanceOf(result);
- Assert.AreEqual(2, result.Items.Count);
+ Assert.AreEqual(1, result.Items.Count);
+ Assert.IsInstanceOf(result.Items[0]);
+ }
+
+ [Test]
+ public void AddSeparator_ItemThenSeparatorThenItemAddedWhenBuild_SeparatorAdded()
+ {
+ // Setup
+ var builder = new ContextMenuBuilder(null, MockRepository.GenerateMock());
+
+ var someItem = new StrictContextMenuItem(null, null, null, null);
+ var someOtherItem = new StrictContextMenuItem(null, null, null, null);
+
+ // Call
+ var result = builder.AddCustomItem(someItem).AddSeparator().AddCustomItem(someOtherItem).Build();
+
+ // Assert
+ Assert.IsInstanceOf(result);
+ Assert.AreEqual(3, result.Items.Count);
+
Assert.IsInstanceOf(result.Items[1]);
}
@@ -364,7 +379,7 @@
// Assert
Assert.IsInstanceOf(result);
- Assert.AreEqual(2, result.Items.Count);
+ Assert.AreEqual(1, result.Items.Count);
}
}
}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs
===================================================================
diff -u -r5bdfe106fefb36f7e677da7e75afec1eba7eedd3 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 5bdfe106fefb36f7e677da7e75afec1eba7eedd3)
+++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -23,20 +23,31 @@
public void Constructor_WithoutCommandHandler_ThrowsArgumentNullException()
{
// Call
- TestDelegate test = () => new GuiContextMenuItemFactory(null);
+ TestDelegate test = () => new GuiContextMenuItemFactory(null, null);
// Assert
var message = Assert.Throws(test).Message;
StringAssert.StartsWith(Resources.GuiContextMenuItemFactory_Can_not_create_gui_context_menu_items_without_gui, message);
StringAssert.EndsWith("commandHandler", message);
+ }
+ [Test]
+ public void Constructor_WithoutTreeNode_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => new GuiContextMenuItemFactory(mocks.StrictMock(), null);
+
+ // Assert
+ var message = Assert.Throws(test).Message;
+ StringAssert.StartsWith(Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node, message);
+ StringAssert.EndsWith("treeNode", message);
}
[Test]
public void Constructor_WithGuiAndTreeNode_NewInstance()
{
// Call
- var result = new GuiContextMenuItemFactory(mocks.StrictMock());
+ var result = new GuiContextMenuItemFactory(mocks.Stub(), mocks.Stub());
// Assert
Assert.IsInstanceOf(result);
@@ -47,9 +58,10 @@
{
// Setup
var guiMock = mocks.StrictMock();
- guiMock.Expect(ch => ch.CanOpenDefaultViewForSelection()).Return(false);
+ var nodeStub = mocks.Stub();
+ guiMock.Expect(ch => ch.CanOpenDefaultViewFor(null)).IgnoreArguments().Return(false);
- var contextMenuFactory = new GuiContextMenuItemFactory(guiMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(guiMock, nodeStub);
mocks.ReplayAll();
@@ -68,9 +80,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanOpenDefaultViewForSelection()).Return(true);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanOpenDefaultViewFor(null)).IgnoreArguments().Return(true);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -89,9 +102,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanExportFromGuiSelection()).Return(false);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanExportFrom(null)).IgnoreArguments().Return(false);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -112,9 +126,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanExportFromGuiSelection()).Return(true);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanExportFrom(null)).IgnoreArguments().Return(true);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -135,9 +150,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanImportToGuiSelection()).Return(false);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanImportOn(null)).IgnoreArguments().Return(false);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -158,9 +174,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanImportToGuiSelection()).Return(true);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanImportOn(null)).IgnoreArguments().Return(true);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -181,9 +198,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanShowPropertiesForGuiSelection()).Return(true);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanShowPropertiesFor(null)).IgnoreArguments().Return(true);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -204,9 +222,10 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanShowPropertiesForGuiSelection()).Return(false);
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanShowPropertiesFor(null)).IgnoreArguments().Return(false);
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
@@ -227,10 +246,11 @@
{
// Setup
var commandHandlerMock = mocks.StrictMock();
- commandHandlerMock.Expect(ch => ch.CanShowPropertiesForGuiSelection()).Return(true);
- commandHandlerMock.Expect(ch => ch.ShowProperties());
+ var nodeStub = mocks.Stub();
+ commandHandlerMock.Expect(ch => ch.CanShowPropertiesFor(null)).IgnoreArguments().Return(true);
+ commandHandlerMock.Expect(ch => ch.ShowPropertiesFor(null)).IgnoreArguments();
- var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock);
+ var contextMenuFactory = new GuiContextMenuItemFactory(commandHandlerMock, nodeStub);
mocks.ReplayAll();
Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/StrictContextMenuItemTest.cs
===================================================================
diff -u -reb7f8fe1e85f00faf16a1cddef014728d60a2b19 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.Test/ContextMenu/StrictContextMenuItemTest.cs (.../StrictContextMenuItemTest.cs) (revision eb7f8fe1e85f00faf16a1cddef014728d60a2b19)
+++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/StrictContextMenuItemTest.cs (.../StrictContextMenuItemTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -1,6 +1,4 @@
using System;
-using System.Drawing;
-using System.IO;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Properties;
using Core.Common.TestUtils;
Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj
===================================================================
diff -u -r7a8e3d1718cb12c53c2b0573b056037ed02e9913 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 7a8e3d1718cb12c53c2b0573b056037ed02e9913)
+++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -62,7 +62,6 @@
-
Index: Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs
===================================================================
diff -u -rb1eb3cb37aaee9ebe020e4a2ca5e9730abfa748a -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs (.../GuiCommandHandlerTest.cs) (revision b1eb3cb37aaee9ebe020e4a2ca5e9730abfa748a)
+++ Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs (.../GuiCommandHandlerTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -19,15 +19,16 @@
{
// Setup
var gui = mocks.DynamicMock();
+ var anObject = new AnObject();
gui.Expect(g => g.Plugins).Return(new GuiPlugin[] {new TestGuiPlugin()});
- gui.Expect(g => g.Selection).Return(new AnObject());
+ gui.Expect(g => g.Selection).Return(anObject);
mocks.ReplayAll();
var guiCommandHandler = new GuiCommandHandler(gui);
// Call
- var canShowProperties = guiCommandHandler.CanShowPropertiesForGuiSelection();
+ var canShowProperties = guiCommandHandler.CanShowPropertiesFor(anObject);
// Assert
Assert.IsTrue(canShowProperties);
@@ -40,15 +41,16 @@
{
// Setup
var gui = mocks.DynamicMock();
+ var aSubObject = new ASubObject();
gui.Expect(g => g.Plugins).Return(new GuiPlugin[] {new TestGuiPlugin()});
- gui.Expect(g => g.Selection).Return(new ASubObject());
+ gui.Expect(g => g.Selection).Return(aSubObject);
mocks.ReplayAll();
var guiCommandHandler = new GuiCommandHandler(gui);
// Call
- var canShowProperties = guiCommandHandler.CanShowPropertiesForGuiSelection();
+ var canShowProperties = guiCommandHandler.CanShowPropertiesFor(aSubObject);
// Assert
Assert.IsTrue(canShowProperties);
Fisheye: Tag 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Gui.Test/TestContextMenuBuilderProviderTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Common/test/Core.Common.Gui.TestUtils/ContextMenu/CustomItemsOnlyContextMenuBuilder.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.TestUtils/ContextMenu/CustomItemsOnlyContextMenuBuilder.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.TestUtils/ContextMenu/CustomItemsOnlyContextMenuBuilder.cs (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -0,0 +1,61 @@
+using System.Windows.Forms;
+using Core.Common.Gui.ContextMenu;
+
+namespace Core.Common.Gui.TestUtils.ContextMenu
+{
+ public class CustomItemsOnlyContextMenuBuilder : IContextMenuBuilder
+ {
+ private readonly ContextMenuStrip contextMenu = new ContextMenuStrip();
+
+ public IContextMenuBuilder AddDeleteItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddExpandAllItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddCollapseAllItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddOpenItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddExportItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddImportItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddPropertiesItem()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddSeparator()
+ {
+ return this;
+ }
+
+ public IContextMenuBuilder AddCustomItem(StrictContextMenuItem item)
+ {
+ contextMenu.Items.Add(item);
+ return this;
+ }
+
+ public ContextMenuStrip Build()
+ {
+ return contextMenu;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.TestUtils/Core.Common.Gui.TestUtils.csproj
===================================================================
diff -u -rb5ea48631445312a26944f9d979c34b9132d16e7 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Common/test/Core.Common.Gui.TestUtils/Core.Common.Gui.TestUtils.csproj (.../Core.Common.Gui.TestUtils.csproj) (revision b5ea48631445312a26944f9d979c34b9132d16e7)
+++ Core/Common/test/Core.Common.Gui.TestUtils/Core.Common.Gui.TestUtils.csproj (.../Core.Common.Gui.TestUtils.csproj) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -46,7 +46,7 @@
full
- none
+ none
bin\Release\
4
x86
@@ -79,8 +79,8 @@
+
-
@@ -96,6 +96,9 @@
..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+
+
+
Fisheye: Tag 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Gui.TestUtils/TestContextMenuBuilderProvider.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/NodePresenters/ProjectNodePresenterTest.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/NodePresenters/ProjectNodePresenterTest.cs (.../ProjectNodePresenterTest.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/NodePresenters/ProjectNodePresenterTest.cs (.../ProjectNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -5,7 +5,9 @@
using Core.Common.Base.Data;
using Core.Common.Controls;
using Core.Common.Gui;
+using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.TestUtils;
+using Core.Common.Gui.TestUtils.ContextMenu;
using Core.Common.TestUtils;
using Core.Plugins.ProjectExplorer.NodePresenters;
using Core.Plugins.ProjectExplorer.Properties;
@@ -62,28 +64,58 @@
}
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void GetContextMenu_Always_ReturnsFourItems(bool commonItemsEnabled)
+ public void GetContextMenu_Always_CallsContextMenuBuilderMethods()
{
// Setup
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
- var nodePresenter = new ProjectNodePresenter(TestContextMenuBuilderProvider.Create(mocks, nodeMock, commonItemsEnabled), mocks.StrictMock());
+ var guiCommandHandlerMock = mocks.StrictMock();
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
+
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
+
mocks.ReplayAll();
+ var nodePresenter = new ProjectNodePresenter(contextMenuBuilderProviderMock, guiCommandHandlerMock);
+
// Call
- var result = nodePresenter.GetContextMenu(nodeMock, new Project());
+ nodePresenter.GetContextMenu(nodeMock, new Project());
// Assert
- Assert.AreEqual(9, result.Items.Count);
+ mocks.VerifyAll();
+ }
+ [Test]
+ public void GetContextMenu_Always_AddsAddItem()
+ {
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var nodeMock = mocks.StrictMock();
+ var guiCommandHandlerMock = mocks.StrictMock();
+
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilder);
+
+ mocks.ReplayAll();
+
+ var nodePresenter = new ProjectNodePresenter(contextMenuBuilderProviderMock, guiCommandHandlerMock);
+
+ // Call
+ var result = nodePresenter.GetContextMenu(nodeMock, new Project());
+
+ // Assert
+ mocks.VerifyAll();
TestHelper.AssertContextMenuStripContainsItem(result, 0, Resources.AddItem, null, Resources.plus);
- TestHelper.AssertContextMenuStripContainsItem(result, 2, CommonGuiResources.Expand_all, CommonGuiResources.Expand_all_ToolTip, CommonGuiResources.ExpandAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(result, 3, CommonGuiResources.Collapse_all, CommonGuiResources.Collapse_all_ToolTip, CommonGuiResources.CollapseAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(result, 5, CommonGuiResources.Import, CommonGuiResources.Import_ToolTip, CommonGuiResources.ImportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(result, 6, CommonGuiResources.Export, CommonGuiResources.Export_ToolTip, CommonGuiResources.ExportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(result, 8, CommonGuiResources.Properties, CommonGuiResources.Properties_ToolTip, CommonGuiResources.PropertiesIcon, commonItemsEnabled);
}
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs (.../CategoryTreeFolderNodePresenterTest.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs (.../CategoryTreeFolderNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -25,13 +25,11 @@
public class CategoryTreeFolderNodePresenterTest
{
private MockRepository mockRepository;
- private IContextMenuBuilderProvider contextMenuBuilderProviderMock;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
- contextMenuBuilderProviderMock = mockRepository.StrictMock();
}
[Test]
@@ -50,12 +48,16 @@
public void DefaultConstructor_ExpectedValues()
{
// Call
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
// Assert
Assert.IsInstanceOf>(nodePresenter);
Assert.AreEqual(typeof(CategoryTreeFolder), nodePresenter.NodeTagType);
Assert.IsNull(nodePresenter.TreeView);
+ mockRepository.VerifyAll();
}
[Test]
@@ -65,12 +67,13 @@
public void UpdateNode_ForCategory_InitializeNode(TreeFolderCategory category)
{
// Setup
- var mocks = new MockRepository();
- var parentNode = mocks.StrictMock();
- var currentNode = mocks.Stub();
+ var parentNode = mockRepository.StrictMock();
+ var currentNode = mockRepository.Stub();
currentNode.ForegroundColor = Color.AliceBlue;
- mocks.ReplayAll();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
var folder = new CategoryTreeFolder("Cool name", new object[0], category);
@@ -81,55 +84,66 @@
Assert.AreEqual(folder.Name, currentNode.Text);
Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), currentNode.ForegroundColor);
TestHelper.AssertImagesAreEqual(GetExpectedIconForCategory(category), currentNode.Image);
- mocks.VerifyAll();
+ mockRepository.VerifyAll();
}
[Test]
public void CanRenamedNode_Always_ReturnFalse()
{
// Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
// Call
var isRenamingAllowed = nodePresenter.CanRenameNode(null);
// Assert
Assert.IsFalse(isRenamingAllowed);
+ mockRepository.VerifyAll();
}
[Test]
public void CanRenamedNodeTo_Always_ReturnFalse()
{
// Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
// Call
var isRenamingAllowed = nodePresenter.CanRenameNodeTo(null, "");
// Assert
Assert.IsFalse(isRenamingAllowed);
+ mockRepository.VerifyAll();
}
[Test]
public void CanRemove_Always_ReturnFalse()
{
// Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
// Call
var isRenamingAllowed = nodePresenter.CanRemove(null, null);
// Assert
Assert.IsFalse(isRenamingAllowed);
+ mockRepository.VerifyAll();
}
[Test]
public void GetChildNodeObjects_FolderHasContents_ReturnContents()
{
// Setup
- var mocks = new MockRepository();
- var node = mocks.StrictMock();
- mocks.ReplayAll();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
var folder = new CategoryTreeFolder("", new[]
{
@@ -144,7 +158,7 @@
// Assert
CollectionAssert.AreEqual(folder.Contents, children);
- mocks.VerifyAll();
+ mockRepository.VerifyAll();
}
[Test]
@@ -154,23 +168,25 @@
{
// Setup
var folder = new CategoryTreeFolder("", new object[0]);
- var mocks = new MockRepository();
- var nodeMock = mocks.StrictMock();
+ var nodeMock = mockRepository.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ var menuBuilderMock = mockRepository.StrictMock();
- var nodePresenter = new CategoryTreeFolderNodePresenter(TestContextMenuBuilderProvider.Create(mocks, nodeMock, commonItemsEnabled));
+ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
- mocks.ReplayAll();
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
- // Call
- var returnedContextMenu = nodePresenter.GetContextMenu(nodeMock, folder);
+ mockRepository.ReplayAll();
- // Assert
- Assert.AreEqual(2, returnedContextMenu.Items.Count);
+ var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock);
- TestHelper.AssertContextMenuStripContainsItem(returnedContextMenu, 0, CoreCommonGuiResources.Expand_all, CoreCommonGuiResources.Expand_all_ToolTip, CoreCommonGuiResources.ExpandAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(returnedContextMenu, 1, CoreCommonGuiResources.Collapse_all, CoreCommonGuiResources.Collapse_all_ToolTip, CoreCommonGuiResources.CollapseAllIcon, commonItemsEnabled);
+ // Call
+ nodePresenter.GetContextMenu(nodeMock, folder);
- mocks.VerifyAll();
+ // Assert
+ mockRepository.VerifyAll();
}
private Image GetExpectedIconForCategory(TreeFolderCategory category)
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs (.../FailureMechanismNodePresenter.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs (.../FailureMechanismNodePresenter.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -32,8 +32,6 @@
protected override ContextMenuStrip GetContextMenu(ITreeNode sender, FailureMechanismPlaceholder nodeData)
{
- ContextMenuBuilder menuBuilder = contextMenuBuilderProvider.Get(sender);
-
var calculateItem = new StrictContextMenuItem(
RingtoetsCommonFormsResources.Calculate_all,
RingtoetsCommonFormsResources.Calculate_all_ToolTip,
@@ -50,19 +48,19 @@
{
Enabled = false
};
- var contextMenu = menuBuilder.AddCustomItem(calculateItem)
- .AddCustomItem(clearOutputItem)
- .AddSeparator()
- .AddExpandAllItem()
- .AddCollapseAllItem()
- .AddSeparator()
- .AddImportItem()
- .AddExportItem()
- .AddSeparator()
- .AddPropertiesItem()
- .Build();
- return contextMenu;
+ return contextMenuBuilderProvider.Get(sender)
+ .AddCustomItem(calculateItem)
+ .AddCustomItem(clearOutputItem)
+ .AddSeparator()
+ .AddExpandAllItem()
+ .AddCollapseAllItem()
+ .AddSeparator()
+ .AddImportItem()
+ .AddExportItem()
+ .AddSeparator()
+ .AddPropertiesItem()
+ .Build();
}
private IEnumerable GetInputs(FailureMechanismPlaceholder nodeData)
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -26,7 +26,7 @@
protected override ContextMenuStrip GetContextMenu(ITreeNode sender, PlaceholderWithReadonlyName nodeData)
{
- ContextMenuBuilder menuBuilder = contextMenuBuilderProvider.Get(sender);
+ IContextMenuBuilder menuBuilder = contextMenuBuilderProvider.Get(sender);
if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder)
{
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs (.../AssessmentSectionBaseNodePresenterTest.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs (.../AssessmentSectionBaseNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -1,14 +1,12 @@
using System;
-using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
-using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Controls;
using Core.Common.Gui;
-using Core.Common.Gui.TestUtils;
+using Core.Common.Gui.ContextMenu;
using Core.Common.TestUtils;
using Core.Common.Utils.Collections;
@@ -29,13 +27,11 @@
public class AssessmentSectionBaseNodePresenterTest
{
private MockRepository mockRepository;
- private IContextMenuBuilderProvider contextMenuBuilderProviderMock;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
- contextMenuBuilderProviderMock = mockRepository.StrictMock();
}
[Test]
@@ -53,13 +49,20 @@
[Test]
public void Constructor_WithParamsSet_NewInstance()
{
+ // Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
+ mockRepository.ReplayAll();
+
// Call
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
// Assert
Assert.IsInstanceOf(nodePresenter);
Assert.IsNull(nodePresenter.TreeView);
Assert.AreEqual(typeof(AssessmentSectionBase), nodePresenter.NodeTagType);
+
+ mockRepository.VerifyAll();
}
[Test]
@@ -70,6 +73,8 @@
var mocks = new MockRepository();
var projectNode = mocks.Stub();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -94,6 +99,7 @@
// Setup
var mocks = new MockRepository();
var assessmentSectionMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
var failureMechanismCollection = new[]
{
@@ -104,6 +110,7 @@
};
assessmentSectionMock.Expect(a => a.GetFailureMechanisms()).Return(failureMechanismCollection);
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -128,6 +135,8 @@
// Setup
var mocks = new MockRepository();
var nodeMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -146,6 +155,8 @@
// Setup
var mocks = new MockRepository();
var nodeMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -164,7 +175,10 @@
// Setup
var mocks = new MockRepository();
var assessmentSectionObserver = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
assessmentSectionObserver.Expect(o => o.UpdateObserver());
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -187,6 +201,8 @@
// Setup
var mocks = new MockRepository();
var nodeMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -204,6 +220,8 @@
// Setup
var mocks = new MockRepository();
var dataMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -224,6 +242,8 @@
var dataMock = mocks.StrictMock();
var sourceMock = mocks.StrictMock();
var targetMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -244,6 +264,8 @@
var dataMock = mocks.StrictMock();
var sourceMock = mocks.StrictMock();
var targetMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -264,6 +286,8 @@
var dataMock = mocks.StrictMock();
var sourceParentNodeMock = mocks.StrictMock();
var targetParentNodeDataMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -281,6 +305,8 @@
// Setup
var mocks = new MockRepository();
var dataMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -299,6 +325,8 @@
var mocks = new MockRepository();
var dataMock = mocks.StrictMock();
var eventArgsMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -317,6 +345,8 @@
var mocks = new MockRepository();
var dataMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -334,8 +364,9 @@
{
// Setup
var mocks = new MockRepository();
-
var observerMock = mocks.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
observerMock.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
@@ -365,6 +396,8 @@
var dataMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
var eventArgsMock = mocks.StrictMock("");
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
mocks.ReplayAll();
var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
@@ -377,33 +410,36 @@
}
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void GetContextMenu_Always_ReturnsNineItems(bool commonItemsEnabled)
+ public void GetContextMenu_Always_CallsContextMenuBuilderMethods()
{
// Setup
var mocks = new MockRepository();
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
- var nodePresenter = new AssessmentSectionBaseNodePresenter(TestContextMenuBuilderProvider.Create(mocks, nodeMock, commonItemsEnabled));
+ menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
+
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
+
mocks.ReplayAll();
+ var nodePresenter = new AssessmentSectionBaseNodePresenter(contextMenuBuilderProviderMock);
+
// Call
- var contextMenu = nodePresenter.GetContextMenu(nodeMock, new DikeAssessmentSection());
+ nodePresenter.GetContextMenu(nodeMock, new DikeAssessmentSection());
// Assert
- Assert.AreEqual(9, contextMenu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, CoreCommonGuiResources.Delete, CoreCommonGuiResources.Delete_ToolTip, CoreCommonGuiResources.DeleteIcon);
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 2, CoreCommonGuiResources.Expand_all, CoreCommonGuiResources.Expand_all_ToolTip, CoreCommonGuiResources.ExpandAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, CoreCommonGuiResources.Collapse_all, CoreCommonGuiResources.Collapse_all_ToolTip, CoreCommonGuiResources.CollapseAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 5, CoreCommonGuiResources.Import, CoreCommonGuiResources.Import_ToolTip, CoreCommonGuiResources.ImportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 6, CoreCommonGuiResources.Export, CoreCommonGuiResources.Export_ToolTip, CoreCommonGuiResources.ExportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(contextMenu, 8, CoreCommonGuiResources.Properties, CoreCommonGuiResources.Properties_ToolTip, CoreCommonGuiResources.PropertiesIcon, commonItemsEnabled);
-
- Assert.IsInstanceOf(contextMenu.Items[1]);
- Assert.IsInstanceOf(contextMenu.Items[4]);
- Assert.IsInstanceOf(contextMenu.Items[7]);
+ mocks.VerifyAll();
}
}
}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/FailureMechanismNodePresenterTest.cs
===================================================================
diff -u -r8a40ed604cff5c3d15f997d51e81002ae160487e -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/FailureMechanismNodePresenterTest.cs (.../FailureMechanismNodePresenterTest.cs) (revision 8a40ed604cff5c3d15f997d51e81002ae160487e)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/FailureMechanismNodePresenterTest.cs (.../FailureMechanismNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -141,72 +141,35 @@
}
[Test]
- [TestCase(true)]
- [TestCase(false)]
- public void GetContextMenu_NoGuiCommandHandler_ReturnsContextMenuWithItems(bool commonItemsEnabled)
+ public void GetContextMenu_NoGuiCommandHandler_CallsContextMenuBuilderMethods()
{
// Setup
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
- var childs = new List();
- if (commonItemsEnabled)
- {
- childs.Add(nodeMock);
- }
- nodeMock.Expect(n => n.Nodes).Return(childs).Repeat.Any();
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(null, nodeMock));
- var nodePresenter = new FailureMechanismNodePresenter(contextMenuProvider);
- var failureMechanism = new FailureMechanismPlaceholder("test");
+ 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.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
- mocks.ReplayAll();
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
- // Call
- var menu = nodePresenter.GetContextMenu(nodeMock, failureMechanism);
-
- // Assert
- Assert.AreEqual(6, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.Calculate_all, RingtoetsCommonFormsResources.Calculate_all_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.Clear_all_output, RingtoetsCommonFormsResources.Clear_all_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 3, CommonResources.Expand_all, CommonResources.Expand_all_ToolTip, CommonResources.ExpandAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(menu, 4, CommonResources.Collapse_all, CommonResources.Collapse_all_ToolTip, CommonResources.CollapseAllIcon, commonItemsEnabled);
-
- CollectionAssert.AllItemsAreInstancesOfType(new []{menu.Items[2], menu.Items[5]}, typeof(ToolStripSeparator));
-
- mocks.VerifyAll();
- }
-
- [Test]
- [TestCase(true)]
- [TestCase(false)]
- public void GetContextMenu_WithGuiCommandHandler_ReturnsContextMenuWithCommonItems(bool commonItemsEnabled)
- {
- // Setup
- var nodeMock = mocks.Stub();
-
- var nodePresenter = new FailureMechanismNodePresenter(TestContextMenuBuilderProvider.Create(mocks, nodeMock, commonItemsEnabled));
- var failureMechanism = new FailureMechanismPlaceholder("test");
- nodeMock.Tag = failureMechanism;
-
mocks.ReplayAll();
+ var nodePresenter = new FailureMechanismNodePresenter(contextMenuBuilderProviderMock);
+
// Call
- var menu = nodePresenter.GetContextMenu(nodeMock, failureMechanism);
+ nodePresenter.GetContextMenu(nodeMock, new FailureMechanismPlaceholder("test"));
// Assert
- Assert.AreEqual(10, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.Calculate_all, RingtoetsCommonFormsResources.Calculate_all_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.Clear_all_output, RingtoetsCommonFormsResources.Clear_all_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 3, CommonResources.Expand_all, CommonResources.Expand_all_ToolTip, CommonResources.ExpandAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(menu, 4, CommonResources.Collapse_all, CommonResources.Collapse_all_ToolTip, CommonResources.CollapseAllIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(menu, 6, CommonResources.Import, CommonResources.Import_ToolTip, CommonResources.ImportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(menu, 7, CommonResources.Export, CommonResources.Export_ToolTip, CommonResources.ExportIcon, commonItemsEnabled);
- TestHelper.AssertContextMenuStripContainsItem(menu, 9, CommonResources.Properties, CommonResources.Properties_ToolTip, CommonResources.PropertiesIcon, commonItemsEnabled);
-
- CollectionAssert.AllItemsAreInstancesOfType(new []{menu.Items[2]}, typeof(ToolStripSeparator));
-
mocks.VerifyAll();
}
}
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/PlaceholderWithReadonlyNameNodePresenterTest.cs
===================================================================
diff -u -r5bdfe106fefb36f7e677da7e75afec1eba7eedd3 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/PlaceholderWithReadonlyNameNodePresenterTest.cs (.../PlaceholderWithReadonlyNameNodePresenterTest.cs) (revision 5bdfe106fefb36f7e677da7e75afec1eba7eedd3)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/PlaceholderWithReadonlyNameNodePresenterTest.cs (.../PlaceholderWithReadonlyNameNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -171,172 +171,89 @@
}
[Test]
- public void GetContextMenu_PlaceholderWithReadonlyNameNoGui_ReturnsEmptyContextMenu()
+ public void GetContextMenu_OutputPlaceHolder_CallsContextMenuBuilderMethods()
{
// Setup
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(null, nodeMock)); ;
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new PlaceholderWithReadonlyName("test");
+ menuBuilderMock.Expect(mb => mb.AddOpenItem()).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
- mocks.ReplayAll();
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
- // Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
-
- // Assert
- Assert.AreEqual(0, menu.Items.Count);
-
- mocks.VerifyAll();
- }
-
- [Test]
- public void GetContextMenu_InputPlaceHolderNoGui_ReturnsContextMenuWithItems()
- {
- // Setup
- var nodeMock = mocks.StrictMock();
- var contextMenuProvider = mocks.StrictMock();
-
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(null, nodeMock)); ;
-
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new InputPlaceholder("test");
-
mocks.ReplayAll();
+ var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuBuilderProviderMock);
+
// Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
+ nodePresenter.GetContextMenu(nodeMock, new OutputPlaceholder("test"));
// Assert
- Assert.AreEqual(2, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
-
- CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[1] }, typeof(ToolStripSeparator));
-
mocks.VerifyAll();
}
[Test]
- public void GetContextMenu_OutputPlaceHolderNoGui_ReturnsContextMenuWithItems()
+ public void GetContextMenu_InputPlaceHolder_CallsContextMenuBuilderMethods()
{
// Setup
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
var nodeMock = mocks.StrictMock();
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(null, nodeMock));
+ menuBuilderMock.Expect(mb => mb.AddOpenItem()).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new OutputPlaceholder("test");
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
mocks.ReplayAll();
- // Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
+ var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuBuilderProviderMock);
- // Assert
- Assert.AreEqual(2, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
-
- CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[1] }, typeof(ToolStripSeparator));
-
- mocks.VerifyAll();
- }
-
- [Test]
- public void GetContextMenu_InputPlaceHolderWithGui_ReturnsContextMenuWithItems()
- {
- // Setup
- var nodeMock = mocks.Stub();
- var guiHandlerMock = mocks.DynamicMock();
-
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(guiHandlerMock, nodeMock));
-
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new InputPlaceholder("test");
-
- mocks.ReplayAll();
-
// Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
+ nodePresenter.GetContextMenu(nodeMock, new InputPlaceholder("test"));
// Assert
- Assert.AreEqual(7, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, CommonResources.Open, CommonResources.Open_ToolTip, CommonResources.OpenIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 3, CommonResources.Import, CommonResources.Import_ToolTip, CommonResources.ImportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 4, CommonResources.Export, CommonResources.Export_ToolTip, CommonResources.ExportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 6, CommonResources.Properties, CommonResources.Properties_ToolTip, CommonResources.PropertiesIcon, false);
-
- CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[5] }, typeof(ToolStripSeparator));
-
mocks.VerifyAll();
}
[Test]
- public void GetContextMenu_OutputPlaceHolderWithGui_ReturnsContextMenuWithItems()
+ public void GetContextMenu_PlaceHolder_CallsContextMenuBuilderMethods()
{
// Setup
- var nodeMock = mocks.Stub();
- var guiHandlerMock = mocks.DynamicMock();
+ var contextMenuBuilderProviderMock = mocks.StrictMock();
+ var menuBuilderMock = mocks.StrictMock();
+ var nodeMock = mocks.StrictMock();
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(guiHandlerMock, nodeMock));
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new OutputPlaceholder("test");
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
mocks.ReplayAll();
- // Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
+ var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuBuilderProviderMock);
- // Assert
- Assert.AreEqual(7, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, CommonResources.Open, CommonResources.Open_ToolTip, CommonResources.OpenIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 3, CommonResources.Import, CommonResources.Import_ToolTip, CommonResources.ImportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 4, CommonResources.Export, CommonResources.Export_ToolTip, CommonResources.ExportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 6, CommonResources.Properties, CommonResources.Properties_ToolTip, CommonResources.PropertiesIcon, false);
-
- CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[5] }, typeof(ToolStripSeparator));
-
- mocks.VerifyAll();
- }
-
- [Test]
- public void GetContextMenu_PlaceholderWithReadonlyNameWithGui_ReturnsContextMenuWithItems()
- {
- // Setup
- var nodeMock = mocks.Stub();
- var guiHandlerMock = mocks.DynamicMock();
-
- var contextMenuProvider = mocks.StrictMock();
- contextMenuProvider.Expect(cmp => cmp.Get(null)).IgnoreArguments().Return(new ContextMenuBuilder(guiHandlerMock, nodeMock));
-
- var nodePresenter = new PlaceholderWithReadonlyNameNodePresenter(contextMenuProvider);
- var placeholderData = new PlaceholderWithReadonlyName("test");
-
- mocks.ReplayAll();
-
// Call
- var menu = nodePresenter.GetContextMenu(nodeMock, placeholderData);
+ nodePresenter.GetContextMenu(nodeMock, new PlaceholderWithReadonlyName("test"));
// Assert
- Assert.AreEqual(4, menu.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(menu, 0, CommonResources.Import, CommonResources.Import_ToolTip, CommonResources.ImportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 1, CommonResources.Export, CommonResources.Export_ToolTip, CommonResources.ExportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(menu, 3, CommonResources.Properties, CommonResources.Properties_ToolTip, CommonResources.PropertiesIcon, false);
-
- CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2] }, typeof(ToolStripSeparator));
-
mocks.VerifyAll();
}
}
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingInputContextNodePresenterTest.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingInputContextNodePresenterTest.cs (.../PipingInputContextNodePresenterTest.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingInputContextNodePresenterTest.cs (.../PipingInputContextNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -3,6 +3,7 @@
using System.Windows.Forms;
using Core.Common.Controls;
using Core.Common.Gui;
+using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.TestUtils;
using Core.Common.TestUtils;
@@ -23,13 +24,11 @@
public class PipingInputContextNodePresenterTest
{
private MockRepository mockRepository;
- private IContextMenuBuilderProvider contextMenuBuilderProviderMock;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
- contextMenuBuilderProviderMock = mockRepository.StrictMock();
}
[Test]
@@ -47,6 +46,11 @@
[Test]
public void Constructor_WithParamsSet_ExpectedValues()
{
+ // Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
+ mockRepository.ReplayAll();
+
// Call
var nodePresenter = new PipingInputContextNodePresenter(contextMenuBuilderProviderMock);
@@ -60,11 +64,11 @@
public void UpdateNode_WithInputParametersData_InitializeNode()
{
// Setup
- var mocks = new MockRepository();
- var parentNode = mocks.StrictMock();
- var currentNode = mocks.Stub();
+ var parentNode = mockRepository.StrictMock();
+ var currentNode = mockRepository.Stub();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
currentNode.ForegroundColor = Color.AliceBlue;
- mocks.ReplayAll();
+ mockRepository.ReplayAll();
var nodeData = new PipingInputContext();
@@ -77,16 +81,16 @@
Assert.AreEqual("Invoer", currentNode.Text);
Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), currentNode.ForegroundColor);
TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingInputIcon, currentNode.Image);
- mocks.VerifyAll();
+ mockRepository.VerifyAll();
}
[Test]
public void CanRenameNode_Always_ReturnFalse()
{
// Setup
- var mocks = new MockRepository();
- var currentNode = mocks.StrictMock();
- mocks.ReplayAll();
+ var currentNode = mockRepository.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
var nodePresenter = new PipingInputContextNodePresenter(contextMenuBuilderProviderMock);
@@ -95,16 +99,16 @@
// Assert
Assert.IsFalse(isRenameAllowed);
- mocks.VerifyAll(); // Expect no calls on mocks.
+ mockRepository.VerifyAll(); // Expect no calls on mocks.
}
[Test]
public void CanRenameNodeTo_Always_ReturnFalse()
{
// Setup
- var mocks = new MockRepository();
- var currentNode = mocks.StrictMock();
- mocks.ReplayAll();
+ var currentNode = mockRepository.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
var nodePresenter = new PipingInputContextNodePresenter(contextMenuBuilderProviderMock);
@@ -113,16 +117,16 @@
// Assert
Assert.IsFalse(isRenameAllowed);
- mocks.VerifyAll(); // Expect no calls on mocks.
+ mockRepository.VerifyAll(); // Expect no calls on mocks.
}
[Test]
public void CanRemove_Always_ReturnFalse()
{
// Setup
- var mocks = new MockRepository();
- var currentNode = mocks.StrictMock();
- mocks.ReplayAll();
+ var currentNode = mockRepository.StrictMock();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
var nodeData = new PipingInputContext();
@@ -133,29 +137,34 @@
// Assert
Assert.IsFalse(isRemoveAllowed);
- mocks.VerifyAll(); // Expect no calls on mocks.
+ mockRepository.VerifyAll(); // Expect no calls on mocks.
}
[Test]
- public void GetContextMenu_MenuBuilderProvider_ReturnsFourItems()
+ public void GetContextMenu_Always_CallsContextMenuBuilderMethods()
{
// Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ var menuBuilderMock = mockRepository.StrictMock();
var nodeMock = mockRepository.StrictMock();
- var nodePresenter = new PipingInputContextNodePresenter(TestContextMenuBuilderProvider.Create(mockRepository, nodeMock));
+ menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
+
+ contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock);
+
mockRepository.ReplayAll();
+ var nodePresenter = new PipingInputContextNodePresenter(contextMenuBuilderProviderMock);
+
// Call
- var result = nodePresenter.GetContextMenu(nodeMock, new PipingInputContext());
+ nodePresenter.GetContextMenu(nodeMock, new PipingInputContext());
// Assert
- Assert.AreEqual(4, result.Items.Count);
-
- TestHelper.AssertContextMenuStripContainsItem(result, 0, CommonGuiResources.Import, CommonGuiResources.Import_ToolTip, CommonGuiResources.ImportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(result, 1, CommonGuiResources.Export, CommonGuiResources.Export_ToolTip, CommonGuiResources.ExportIcon, false);
- TestHelper.AssertContextMenuStripContainsItem(result, 3, CommonGuiResources.Properties, CommonGuiResources.Properties_ToolTip, CommonGuiResources.PropertiesIcon, false);
-
- Assert.IsInstanceOf(result.Items[2]);
+ mockRepository.VerifyAll();
}
}
}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingOutputNodePresenterTest.cs
===================================================================
diff -u -rd02fa527769665fe275986468c6ac570fbad5e48 -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingOutputNodePresenterTest.cs (.../PipingOutputNodePresenterTest.cs) (revision d02fa527769665fe275986468c6ac570fbad5e48)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingOutputNodePresenterTest.cs (.../PipingOutputNodePresenterTest.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2)
@@ -2,9 +2,12 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
+using Core.Common.Base;
using Core.Common.Controls;
using Core.Common.Gui;
+using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.TestUtils;
+using Core.Common.Gui.TestUtils.ContextMenu;
using Core.Common.TestUtils;
using NUnit.Framework;
@@ -25,13 +28,11 @@
public class PipingOutputNodePresenterTest
{
private MockRepository mockRepository;
- private IContextMenuBuilderProvider contextMenuBuilderProviderMock;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
- contextMenuBuilderProviderMock = mockRepository.StrictMock();
}
[Test]
@@ -49,13 +50,20 @@
[Test]
public void Constructor_WithParamsSet_NewInstance()
{
+ // Setup
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+
+ mockRepository.ReplayAll();
+
// Call
- var nodePresenter = new PipingOutputNodePresenter(mockRepository.StrictMock());
+ var nodePresenter = new PipingOutputNodePresenter(contextMenuBuilderProviderMock);
// Assert
Assert.IsInstanceOf(nodePresenter);
Assert.IsNull(nodePresenter.TreeView);
Assert.AreEqual(typeof(PipingOutput), nodePresenter.NodeTagType);
+
+ mockRepository.VerifyAll();
}
[Test]
@@ -64,10 +72,10 @@
// Setup
const string outputName = "Piping resultaat";
- var mocks = new MockRepository();
- var pipingNode = mocks.Stub();
+ var contextMenuBuilderProviderMock = mockRepository.StrictMock();
+ var pipingNode = mockRepository.Stub();
pipingNode.ForegroundColor = Color.AliceBlue;
- mocks.ReplayAll();
+ mockRepository.ReplayAll();
var nodePresenter = new PipingOutputNodePresenter(contextMenuBuilderProviderMock);
@@ -86,9 +94,9 @@
public void CanRemove_NotPipingOutput_ThrowsInvalidCastException()
{
// Setup
- var mocks = new MockRepository();
- var dataMock = mocks.StrictMock