Index: Core/Common/src/Core.Common.Gui/ContextMenuItemFactory.cs =================================================================== diff -u -rd626df632ea0fa550e1e0811dce714b9486ee926 -r3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e --- Core/Common/src/Core.Common.Gui/ContextMenuItemFactory.cs (.../ContextMenuItemFactory.cs) (revision d626df632ea0fa550e1e0811dce714b9486ee926) +++ Core/Common/src/Core.Common.Gui/ContextMenuItemFactory.cs (.../ContextMenuItemFactory.cs) (revision 3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e) @@ -45,13 +45,19 @@ public ToolStripItem CreatePropertiesItem(object item) { var propertyInfos = gui.Plugins.SelectMany(p => p.GetPropertyInfos()).Where(pi => pi.ObjectType == item.GetType()); - var newItem = new ToolStripMenuItem(Resources.Properties_Title) + var newItem = new ToolStripMenuItem(Resources.Properties) { ToolTipText = Resources.Properties_ToolTip, Image = Resources.PropertiesIcon, Enabled = propertyInfos.Any() }; + var guiCommandHandler = gui.CommandHandler; + if (guiCommandHandler != null) + { + newItem.Click += (s,e) => guiCommandHandler.ShowProperties(); + } + return newItem; } } Index: Core/Common/test/Core.Common.Gui.Test/ContextMenuItemFactoryTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/ContextMenuItemFactoryTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenuItemFactoryTest.cs (revision 3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e) @@ -0,0 +1,243 @@ +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Core.Common.TestUtils; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Common.Gui.Tests +{ + [TestFixture] + public class ContextMenuItemFactoryTest + { + private MockRepository mocks; + private readonly IList pluginList = new GuiPlugin[] + { + new TestGuiPlugin() + }; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + } + + [Test] + public void CreateExportItem_NoImportersForType_Disabled() + { + // Setup + var guiMock = mocks.StrictMock(); + var applicationCore = new ApplicationCore(); + applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); + guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreateExportItem(""); + + // Assert + Assert.AreEqual(Properties.Resources.Export, item.Text); + Assert.AreEqual(Properties.Resources.Export_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.ExportIcon, item.Image); + Assert.IsFalse(item.Enabled); + } + + [Test] + public void CreateExportItem_ImportersForType_Enabled() + { + // Setup + var guiMock = mocks.StrictMock(); + var applicationCore = new ApplicationCore(); + applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); + guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreateExportItem(0); + + // Assert + Assert.AreEqual(Properties.Resources.Export, item.Text); + Assert.AreEqual(Properties.Resources.Export_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.ExportIcon, item.Image); + Assert.IsTrue(item.Enabled); + } + + [Test] + public void CreateImportItem_NoImportersForType_Disabled() + { + // Setup + var guiMock = mocks.StrictMock(); + var applicationCore = new ApplicationCore(); + applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); + guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreateImportItem(""); + + // Assert + Assert.AreEqual(Properties.Resources.Import, item.Text); + Assert.AreEqual(Properties.Resources.Import_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.ImportIcon, item.Image); + Assert.IsFalse(item.Enabled); + } + + [Test] + public void CreateImportItem_ImportersForType_Enabled() + { + // Setup + var guiMock = mocks.StrictMock(); + var applicationCore = new ApplicationCore(); + applicationCore.AddPlugin(new TestApplicationPlugin(mocks)); + guiMock.Expect(g => g.ApplicationCore).Return(applicationCore); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreateImportItem(0); + + // Assert + Assert.AreEqual(Properties.Resources.Import, item.Text); + Assert.AreEqual(Properties.Resources.Import_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.ImportIcon, item.Image); + Assert.IsTrue(item.Enabled); + } + + [Test] + public void CreatePropertiesItem_PropertieInfoForType_Enabled() + { + // Setup + var guiMock = mocks.StrictMock(); + guiMock.Expect(g => g.Plugins).Return(pluginList); + guiMock.Expect(g => g.CommandHandler).Return(null); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreatePropertiesItem(0); + + // Assert + Assert.AreEqual(Properties.Resources.Properties, item.Text); + Assert.AreEqual(Properties.Resources.Properties_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.PropertiesIcon, item.Image); + Assert.IsTrue(item.Enabled); + + mocks.VerifyAll(); + } + + [Test] + public void CreatePropertiesItem_NoPropertieInfoForType_Disabled() + { + // Setup + var guiMock = mocks.StrictMock(); + guiMock.Expect(g => g.Plugins).Return(pluginList); + guiMock.Expect(g => g.CommandHandler).Return(null); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + // Call + var item = contextMenuFactory.CreatePropertiesItem(""); + + // Assert + Assert.AreEqual(Properties.Resources.Properties, item.Text); + Assert.AreEqual(Properties.Resources.Properties_ToolTip, item.ToolTipText); + TestHelper.AssertImagesAreEqual(Properties.Resources.PropertiesIcon, item.Image); + Assert.IsFalse(item.Enabled); + + mocks.VerifyAll(); + } + + [Test] + public void CreatePropertiesItem_ClickWithoutHandler_NoExceptions() + { + // Setup + var guiMock = mocks.StrictMock(); + guiMock.Expect(g => g.Plugins).Return(pluginList); + guiMock.Expect(g => g.CommandHandler).Return(null); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + var item = contextMenuFactory.CreatePropertiesItem(0); + + // Call & Assert + item.PerformClick(); + + mocks.VerifyAll(); + } + + [Test] + public void CreatePropertiesItem_ClickWithHandler_NoExceptions() + { + // Setup + var guiMock = mocks.StrictMock(); + var commandHandlerMock = mocks.StrictMock(); + guiMock.Expect(g => g.Plugins).Return(pluginList); + guiMock.Expect(g => g.CommandHandler).Return(commandHandlerMock); + commandHandlerMock.Expect(ch => ch.ShowProperties()); + var contextMenuFactory = new ContextMenuItemFactory(guiMock); + + mocks.ReplayAll(); + + var item = contextMenuFactory.CreatePropertiesItem(0); + + // Call & Assert + item.PerformClick(); + + mocks.VerifyAll(); + } + } + + public class TestApplicationPlugin : ApplicationPlugin + { + private readonly IFileExporter exporterMock; + private readonly IFileImporter importerMock; + + public TestApplicationPlugin(MockRepository mocks) + { + var typeList = new[] + { + 0.GetType(), + "".GetType() + }; + exporterMock = mocks.DynamicMock(); + exporterMock.Expect(e => e.CanExportFor(0)).Return(true); + exporterMock.Expect(e => e.CanExportFor("")).Return(false); + exporterMock.Expect(e => e.SourceTypes()).Return(typeList); + importerMock = mocks.DynamicMock(); + importerMock.Expect(e => e.CanImportOn(0)).Return(true); + importerMock.Expect(e => e.CanImportOn("")).Return(false); + importerMock.Expect(e => e.SupportedItemTypes).Return(typeList); + } + + public override IEnumerable GetFileExporters() + { + yield return exporterMock; + } + + public override IEnumerable GetFileImporters() + { + yield return importerMock; + } + } + + public class TestGuiPlugin : GuiPlugin + { + public override IEnumerable GetPropertyInfos() + { + yield return new PropertyInfo + { + ObjectType = typeof(int) + }; + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Tests.csproj =================================================================== diff -u -r8ed458d0460c2bab956a7c3a75c2cdb5c1aae3e6 -r3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Tests.csproj (.../Core.Common.Gui.Tests.csproj) (revision 8ed458d0460c2bab956a7c3a75c2cdb5c1aae3e6) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Tests.csproj (.../Core.Common.Gui.Tests.csproj) (revision 3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e) @@ -44,17 +44,26 @@ + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + + + + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + {30e4c2ae-719e-4d70-9fa9-668a9767fbfa} Core.Common.Gui Index: Core/Common/test/Core.Common.Gui.Test/packages.config =================================================================== diff -u -r3aa69a0ff858d591479a1b33ef1ad36ae76a5052 -r3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e --- Core/Common/test/Core.Common.Gui.Test/packages.config (.../packages.config) (revision 3aa69a0ff858d591479a1b33ef1ad36ae76a5052) +++ Core/Common/test/Core.Common.Gui.Test/packages.config (.../packages.config) (revision 3d0bcb2ef15e3e8e171f75e0a8cfa20a0a2bbd5e) @@ -1,4 +1,5 @@  + \ No newline at end of file