Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r1e9f415cb615bf84526faeecb51f9a70498f9ffc -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -141,6 +141,7 @@ + Index: Core/Common/test/Core.Common.Gui.Test/RingtoetsGuiTests.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/RingtoetsGuiTests.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/RingtoetsGuiTests.cs (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -0,0 +1,319 @@ +using System; +using System.Linq; + +using Core.Common.Base.Plugin; +using Core.Common.Base.Storage; +using Core.Common.Controls.TreeView; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.MessageWindow; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.Test.Forms.ViewManager; + +using NUnit.Framework; + +using Rhino.Mocks; + +namespace Core.Common.Gui.Test +{ + [TestFixture] + public class RingtoetsGuiTests + { + private MessageWindowLogAppender originalAppender; + + [SetUp] + public void SetUp() + { + originalAppender = MessageWindowLogAppender.Instance; + MessageWindowLogAppender.Instance = new MessageWindowLogAppender(); + } + + [TearDown] + public void TearDown() + { + MessageWindowLogAppender.Instance = originalAppender; + } + + [Test] + [STAThread] + public void DisposingGuiDisposesApplication() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var applicationCore = mocks.Stub(); + applicationCore.Expect(ac => ac.Dispose()); + mocks.ReplayAll(); + + var gui = new RingtoetsGui(new MainWindow(), projectStore, applicationCore); + + // Call + gui.Dispose(); + + // Assert + mocks.VerifyAll(); + } + + [Test] + [STAThread] + public void Run_WithFile_LoadProjectFromFile() + { + // Setup + var testFile = "SomeFile"; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + projectStore.Expect(ps => ps.LoadProject(testFile)); + mocks.ReplayAll(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + // Call + gui.Run(testFile); + + // Assert + Assert.AreEqual(testFile, gui.ProjectFilePath); + } + mocks.VerifyAll(); + } + + [Test] + [STAThread] + public void CheckViewPropertyEditorIsInitialized() + { + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (new RingtoetsGui(new MainWindow(), projectStore)) + { + Assert.NotNull(ViewPropertyEditor.ViewCommands); + } + mocks.VerifyAll(); + } + + [Test] + [STAThread] + public void GetAllDataWithViewDefinitionsRecursively_DataHasNoViewDefinitions_ReturnEmpty() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var ringtoetsGui = new RingtoetsGui(new MainWindow(), projectStore)) + { + var rootData = new object(); + + // Call + var dataInstancesWithViewDefinitions = ringtoetsGui.GetAllDataWithViewDefinitionsRecursively(rootData); + + // Assert + CollectionAssert.IsEmpty(dataInstancesWithViewDefinitions); + } + mocks.VerifyAll(); + } + + [Test] + [STAThread] + public void GetAllDataWithViewDefinitionsRecursively_MultiplePluginsHaveViewDefinitionsForRoot_ReturnRootObject() + { + // Setup + var rootData = new object(); + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + + var plugin1 = mocks.StrictMock(); + plugin1.Expect(p => p.GetChildDataWithViewDefinitions(rootData)).Return(new[] + { + rootData + }); + plugin1.Stub(p => p.Dispose()); + plugin1.Stub(p => p.Deactivate()); + var plugin2 = mocks.StrictMock(); + plugin2.Expect(p => p.GetChildDataWithViewDefinitions(rootData)).Return(new[] + { + rootData + }); + plugin2.Stub(p => p.Dispose()); + plugin2.Stub(p => p.Deactivate()); + mocks.ReplayAll(); + + using (var ringtoetsGui = new RingtoetsGui(new MainWindow(), projectStore)) + { + ringtoetsGui.Plugins.Add(plugin1); + ringtoetsGui.Plugins.Add(plugin2); + + // Call + var dataInstancesWithViewDefinitions = ringtoetsGui.GetAllDataWithViewDefinitionsRecursively(rootData).OfType().ToArray(); + + // Assert + var expectedDataDefinitions = new[] + { + rootData + }; + CollectionAssert.AreEquivalent(expectedDataDefinitions, dataInstancesWithViewDefinitions); + } + mocks.VerifyAll(); + } + + [Test] + [STAThread] + public void GetAllDataWithViewDefinitionsRecursively_MultiplePluginsHaveViewDefinitionsForRootAndChild_ReturnRootAndChild() + { + // Setup + object rootData = 1; + object rootChild = 2; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var plugin1 = mocks.StrictMock(); + plugin1.Expect(p => p.GetChildDataWithViewDefinitions(rootData)).Return(new[] + { + rootData, rootChild + }); + plugin1.Expect(p => p.GetChildDataWithViewDefinitions(rootChild)).Return(new[] + { + rootChild + }); + plugin1.Stub(p => p.Dispose()); + plugin1.Stub(p => p.Deactivate()); + var plugin2 = mocks.StrictMock(); + plugin2.Expect(p => p.GetChildDataWithViewDefinitions(rootData)).Return(new[] + { + rootChild, rootData + }); + plugin2.Expect(p => p.GetChildDataWithViewDefinitions(rootChild)).Return(new[] + { + rootChild + }); + plugin2.Stub(p => p.Dispose()); + plugin2.Stub(p => p.Deactivate()); + mocks.ReplayAll(); + + using (var ringtoetsGui = new RingtoetsGui(new MainWindow(), projectStore)) + { + ringtoetsGui.Plugins.Add(plugin1); + ringtoetsGui.Plugins.Add(plugin2); + + // Call + var dataInstancesWithViewDefinitions = ringtoetsGui.GetAllDataWithViewDefinitionsRecursively(rootData).OfType().ToArray(); + + // Assert + var expectedDataDefinitions = new[] + { + rootData, rootChild + }; + CollectionAssert.AreEquivalent(expectedDataDefinitions, dataInstancesWithViewDefinitions); + } + mocks.VerifyAll(); + } + + [Test] + [RequiresSTA] + public void ActiveViewChanged_LastDocumentViewClosed_EventFired() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + gui.Run(); + + var view = new TestView(); + + // Precondition + Assert.AreEqual(0, gui.DocumentViews.Count); + + gui.DocumentViews.Add(view); + + var hitCount = 0; + gui.ActiveViewChanged += (s, e) => hitCount++; + + // Call + gui.DocumentViews.RemoveAt(0); + + // Assert + Assert.AreEqual(0, gui.DocumentViews.Count); + Assert.AreEqual(1, hitCount); + } + mocks.VerifyAll(); + } + + [Test] + [RequiresSTA] + public void GetTreeNodeInfos_NoPluginsConfigured_EmptyList() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + // Call + var result = gui.GetTreeNodeInfos(); + + // Assert + CollectionAssert.IsEmpty(result); + } + } + + [Test] + [RequiresSTA] + public void GetTreeNodeInfos_MultiplePluginsConfigured_RetrievesTreeNodeInfosFromPlugins() + { + // Setup + var nodesPluginA = new[] + { + new TreeNodeInfo(), + new TreeNodeInfo() + }; + var nodesPluginB = new[] + { + new TreeNodeInfo(), + }; + var nodesPluginC = new[] + { + new TreeNodeInfo(), + new TreeNodeInfo(), + new TreeNodeInfo(), + }; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + + var pluginA = mocks.Stub(); + pluginA.Stub(p => p.GetTreeNodeInfos()).Return(nodesPluginA); + pluginA.Stub(p => p.Dispose()); + pluginA.Stub(p => p.Deactivate()); + var pluginB = mocks.Stub(); + pluginB.Stub(p => p.GetTreeNodeInfos()).Return(nodesPluginB); + pluginB.Stub(p => p.Dispose()); + pluginB.Stub(p => p.Deactivate()); + var pluginC = mocks.Stub(); + pluginC.Stub(p => p.GetTreeNodeInfos()).Return(nodesPluginC); + pluginC.Stub(p => p.Dispose()); + pluginC.Stub(p => p.Deactivate()); + mocks.ReplayAll(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + gui.Plugins.Add(pluginA); + gui.Plugins.Add(pluginB); + gui.Plugins.Add(pluginC); + + // Call + var result = gui.GetTreeNodeInfos(); + + // Assert + var expected = nodesPluginA.Concat(nodesPluginB).Concat(nodesPluginC); + CollectionAssert.AreEquivalent(expected, result); + } + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Test/Core.Common.Test.csproj =================================================================== diff -u -r1e9f415cb615bf84526faeecb51f9a70498f9ffc -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Common/test/Core.Common.Test/Core.Common.Test.csproj (.../Core.Common.Test.csproj) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc) +++ Core/Common/test/Core.Common.Test/Core.Common.Test.csproj (.../Core.Common.Test.csproj) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -98,7 +98,6 @@ - True True Fisheye: Tag e4ee8a21ab07f3446dc417e50574b6bc6106f460 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Test/Gui/RingtoetsGuiTests.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs (.../LegendController.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs (.../LegendController.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -35,6 +35,9 @@ private readonly IToolViewController toolViewController; private IView legendView; + /// + /// Fired when the legend has been opened. + /// public EventHandler OnOpenLegend; /// Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj =================================================================== diff -u -rc37787efa31f4a9aa6df2ace311109ccd21d96fd -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj (.../Core.Plugins.ProjectExplorer.csproj) (revision c37787efa31f4a9aa6df2ace311109ccd21d96fd) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj (.../Core.Plugins.ProjectExplorer.csproj) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -63,10 +63,6 @@ AllRules.ruleset - - - - False ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Fluent.dll @@ -77,7 +73,6 @@ 3.5 - @@ -129,11 +124,6 @@ Core.Common.Gui False - - {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} - Core.Common.Utils - False - {c90b77da-e421-43cc-b82e-529651bc21ac} Core.Common.Version Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerViewController.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerViewController.cs (.../ProjectExplorerViewController.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerViewController.cs (.../ProjectExplorerViewController.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; + using Core.Common.Base.Data; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -39,9 +40,12 @@ private readonly IApplicationSelection applicationSelection; private readonly IViewCommands viewCommands; private readonly IDocumentViewController documentViewController; + private ProjectExplorer projectExplorer; + /// + /// Fired when the project explorer view has been opened. + /// public EventHandler OnOpenView; - private ProjectExplorer projectExplorer; /// /// Creates a new instance of . @@ -107,7 +111,7 @@ } /// - /// Makes the visisble. + /// Makes the visible. /// public void OpenView() { @@ -128,7 +132,6 @@ /// /// Returns a value indicating whether the is visible. /// - /// public bool IsViewActive() { return toolViewController.IsToolWindowOpen(); @@ -153,9 +156,13 @@ private void CloseView() { - if (IsViewActive()) + if (projectExplorer != null && IsViewActive()) { - toolViewController.CloseToolView(projectExplorer); // Disposes the view. + toolViewController.CloseToolView(projectExplorer); + if (!projectExplorer.IsDisposed) + { + projectExplorer.Dispose(); + } projectExplorer = null; } } Index: Core/Plugins/test/Core.Plugins.CommonTools.Test/CommonToolsGuiPluginTest.cs =================================================================== diff -u -rf4a633bf7b75c0e25f0c5bcd600df6def184962c -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/test/Core.Plugins.CommonTools.Test/CommonToolsGuiPluginTest.cs (.../CommonToolsGuiPluginTest.cs) (revision f4a633bf7b75c0e25f0c5bcd600df6def184962c) +++ Core/Plugins/test/Core.Plugins.CommonTools.Test/CommonToolsGuiPluginTest.cs (.../CommonToolsGuiPluginTest.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -39,11 +39,11 @@ var guiPlugin = new CommonToolsGuiPlugin(); // Call - var viewInfos = guiPlugin.GetViewInfoObjects().ToList(); + var viewInfos = guiPlugin.GetViewInfoObjects().ToArray(); // Assert Assert.NotNull(viewInfos); - Assert.AreEqual(2, viewInfos.Count); + Assert.AreEqual(2, viewInfos.Length); var richTextFileInfo = viewInfos.First(vi => vi.DataType == typeof(RichTextFile)); var webLinkInfo = viewInfos.First(vi => vi.DataType == typeof(WebLink)); @@ -62,9 +62,8 @@ { // Setup var guiPlugin = new CommonToolsGuiPlugin(); - var viewInfos = guiPlugin.GetViewInfoObjects().ToList(); - var info = viewInfos.First(vi => vi.DataType == typeof(RichTextFile)); + var info = guiPlugin.GetViewInfoObjects().First(vi => vi.DataType == typeof(RichTextFile)); // Call var name = info.GetViewName(null, null); @@ -79,9 +78,8 @@ // Setup var expected = "SomeName"; var guiPlugin = new CommonToolsGuiPlugin(); - var viewInfos = guiPlugin.GetViewInfoObjects().ToList(); - var info = viewInfos.First(vi => vi.DataType == typeof(RichTextFile)); + var info = guiPlugin.GetViewInfoObjects().First(vi => vi.DataType == typeof(RichTextFile)); var richTextFile = new RichTextFile { Name = expected @@ -99,9 +97,8 @@ { // Setup var guiPlugin = new CommonToolsGuiPlugin(); - var viewInfos = guiPlugin.GetViewInfoObjects().ToList(); - var info = viewInfos.First(vi => vi.DataType == typeof(WebLink)); + var info = guiPlugin.GetViewInfoObjects().First(vi => vi.DataType == typeof(WebLink)); // Call var name = info.GetViewName(null, null); @@ -116,9 +113,8 @@ // Setup var expected = "SomeName"; var guiPlugin = new CommonToolsGuiPlugin(); - var viewInfos = guiPlugin.GetViewInfoObjects().ToList(); - var info = viewInfos.First(vi => vi.DataType == typeof(WebLink)); + var info = guiPlugin.GetViewInfoObjects().First(vi => vi.DataType == typeof(WebLink)); var webLink = new WebLink(expected, null); // Call Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Commands/ToggleProjectExplorerCommandTest.cs =================================================================== diff -u -rdaac7f75692224f6ad3b765cb0b3d8117c1165a6 -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Commands/ToggleProjectExplorerCommandTest.cs (.../ToggleProjectExplorerCommandTest.cs) (revision daac7f75692224f6ad3b765cb0b3d8117c1165a6) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Commands/ToggleProjectExplorerCommandTest.cs (.../ToggleProjectExplorerCommandTest.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -91,23 +91,35 @@ var documentViewController = mocks.StrictMock(); var viewCommands = mocks.StrictMock(); var applicationSelection = mocks.StrictMock(); + applicationSelection.Expect(a => a.SelectionChanged += null).IgnoreArguments(); + var toolViewController = mocks.StrictMock(); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(isViewOpen).Repeat.Twice(); + bool explorerViewActuallyOpened = false; if (isViewOpen) { - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(x => true))); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()) + .Return(false) + .WhenCalled(invocation => invocation.ReturnValue = explorerViewActuallyOpened); + toolViewController.Stub(tvc => tvc.OpenToolView(Arg.Is.TypeOf)); + toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Is.TypeOf)); + applicationSelection.Expect(a => a.SelectionChanged -= null).IgnoreArguments(); } else { - applicationSelection.Expect(a => a.SelectionChanged += null).IgnoreArguments(); - toolViewController.Expect(tvc => tvc.OpenToolView(Arg.Matches(x => true))); + toolViewController.Expect(tvc => tvc.OpenToolView(Arg.Is.TypeOf)); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()).Return(false); } mocks.ReplayAll(); var treeNodeInfos = Enumerable.Empty(); var explorerViewController = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos); + if (isViewOpen) + { + explorerViewController.OpenView(); + explorerViewActuallyOpened = true; + } var command = new ToggleProjectExplorerCommand(explorerViewController); Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs =================================================================== diff -u -rdaac7f75692224f6ad3b765cb0b3d8117c1165a6 -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision daac7f75692224f6ad3b765cb0b3d8117c1165a6) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -35,37 +35,31 @@ { // Setup var mocks = new MockRepository(); - var gui = mocks.StrictMock(); - var otherGuiPlugin = mocks.StrictMock(); + using (var projectExplorerGuiPlugin = new ProjectExplorerGuiPlugin()) + { + var gui = mocks.StrictMock(); + var otherGuiPlugin = mocks.StrictMock(); - gui.Expect(g => g.ViewCommands).Return(mocks.Stub()); - gui.Expect(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); + gui.Expect(g => g.ViewCommands).Return(mocks.Stub()); + gui.Expect(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - gui.Expect(g => g.IsToolWindowOpen()).Return(true).Repeat.Twice(); - gui.Expect(g => g.CloseToolView(Arg.Matches(r => true))); + gui.Expect(g => g.IsToolWindowOpen()).Return(true); - gui.Expect(g => g.ProjectOpened += Arg>.Is.Anything); - gui.Expect(g => g.ProjectOpened -= Arg>.Is.Anything); + gui.Expect(g => g.ProjectOpened += Arg>.Is.Anything); + gui.Expect(g => g.ProjectOpened -= Arg>.Is.Anything); - gui.Replay(); - - using (var projectExplorerGuiPlugin = new ProjectExplorerGuiPlugin - { - Gui = gui - }) - { gui.Expect(g => g.Plugins).Return(new List { projectExplorerGuiPlugin, otherGuiPlugin }).Repeat.Any(); mocks.ReplayAll(); + projectExplorerGuiPlugin.Gui = gui; + // Call projectExplorerGuiPlugin.Activate(); } - - // Assert mocks.VerifyAll(); } @@ -91,21 +85,18 @@ { // Setup var mocks = new MockRepository(); - var guiStub = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); + guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); + guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); + guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); - using (mocks.Ordered()) - { - guiStub.Expect(g => g.IsToolWindowOpen()).Return(true); - guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); - guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); - guiStub.Expect(g => g.IsToolWindowOpen()).Return(false); - } - + guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); + guiStub.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); using (var plugin = new ProjectExplorerGuiPlugin @@ -127,21 +118,17 @@ { // Setup var mocks = new MockRepository(); - var guiStub = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - - using (mocks.Ordered()) - { - guiStub.Expect(g => g.IsToolWindowOpen()).Return(true); - guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); - guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); - guiStub.Expect(g => g.IsToolWindowOpen()).Return(false); - } - + guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); + guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); + guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); + guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiStub.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); using (var plugin = new ProjectExplorerGuiPlugin @@ -168,21 +155,18 @@ { // Setup var mocks = new MockRepository(); - var guiStub = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); + guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); + guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); + guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); + guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - using (mocks.Ordered()) - { - guiStub.Expect(g => g.IsToolWindowOpen()).Return(true); - guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); - guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); - guiStub.Expect(g => g.IsToolWindowOpen()).Return(false); - } - + guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); using (var plugin = new ProjectExplorerGuiPlugin @@ -334,6 +318,7 @@ guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); guiStub.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); guiStub.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); + guiStub.Expect(a => a.SelectionChanged -= null).IgnoreArguments(); } mocks.ReplayAll(); Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerViewControllerTest.cs =================================================================== diff -u -rdaac7f75692224f6ad3b765cb0b3d8117c1165a6 -re4ee8a21ab07f3446dc417e50574b6bc6106f460 --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerViewControllerTest.cs (.../ProjectExplorerViewControllerTest.cs) (revision daac7f75692224f6ad3b765cb0b3d8117c1165a6) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerViewControllerTest.cs (.../ProjectExplorerViewControllerTest.cs) (revision e4ee8a21ab07f3446dc417e50574b6bc6106f460) @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Windows.Forms; + using Core.Common.Base.Data; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -50,9 +52,6 @@ IApplicationSelection applicationSelection = mocks.StrictMock(); IToolViewController toolViewController = mocks.StrictMock(); IEnumerable treeNodeInfos = Enumerable.Empty(); - - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - mocks.ReplayAll(); // Call @@ -69,19 +68,15 @@ { // Setup var mocks = new MockRepository(); - IDocumentViewController documentViewController = mocks.StrictMock(); - IViewCommands viewCommands = mocks.StrictMock(); - IApplicationSelection applicationSelection = mocks.StrictMock(); + IDocumentViewController documentViewController = mocks.Stub(); + IViewCommands viewCommands = mocks.Stub(); + IApplicationSelection applicationSelection = mocks.Stub(); IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); - - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - } + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()).Return(true); mocks.ReplayAll(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { // Call @@ -151,25 +146,28 @@ public void ToggleView_ViewActive_ViewClosed() { // Setup + bool projectExplorerHasBeenOpened = false; + var mocks = new MockRepository(); IDocumentViewController documentViewController = mocks.StrictMock(); IViewCommands viewCommands = mocks.StrictMock(); - IApplicationSelection applicationSelection = mocks.StrictMock(); + IApplicationSelection applicationSelection = mocks.Stub(); IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()) + .Return(false) + .WhenCalled(invocation => invocation.ReturnValue = projectExplorerHasBeenOpened); + toolViewController.Stub(tvc => tvc.OpenToolView(Arg.Is.TypeOf)); + toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Is.TypeOf)); - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - } - mocks.ReplayAll(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { + controller.OpenView(); + projectExplorerHasBeenOpened = true; + // Call controller.ToggleView(); } @@ -181,29 +179,29 @@ public void ToggleView_ViewInactive_ViewOpened() { // Setup + bool viewOpened = false; + var mocks = new MockRepository(); IDocumentViewController documentViewController = mocks.StrictMock(); IViewCommands viewCommands = mocks.StrictMock(); - IApplicationSelection applicationSelection = mocks.StrictMock(); + IApplicationSelection applicationSelection = mocks.Stub(); IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()) + .Return(false) + .WhenCalled(invocation => invocation.ReturnValue = viewOpened); + toolViewController.Expect(tvc => tvc.OpenToolView(Arg.Is.TypeOf)); + toolViewController.Stub(tvc => tvc.CloseToolView(Arg.Is.TypeOf)); - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - applicationSelection.Expect(a => a.SelectionChanged += null).IgnoreArguments(); - toolViewController.Expect(tvc => tvc.OpenToolView(Arg.Matches(v => true))); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - } - mocks.ReplayAll(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { // Call controller.ToggleView(); + + viewOpened = true; } // Assert mocks.VerifyAll(); @@ -220,16 +218,12 @@ IViewCommands viewCommands = mocks.StrictMock(); IApplicationSelection applicationSelection = mocks.StrictMock(); IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()).Return(isOpen); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(isOpen).Repeat.Twice(); - if (isOpen) - { - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - } - mocks.ReplayAll(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { // Call @@ -245,11 +239,25 @@ public void Update_ViewIsOpen_UpdateData() { // Setup + ProjectExplorer projectExplorer = null; + bool viewOpened = false; + var mocks = new MockRepository(); - IDocumentViewController documentViewController = mocks.StrictMock(); IViewCommands viewCommands = mocks.StrictMock(); - IApplicationSelection applicationSelection = mocks.StrictMock(); - IToolViewController toolViewController = mocks.StrictMock(); + IApplicationSelection applicationSelection = mocks.Stub(); + + IDocumentViewController documentViewController = mocks.StrictMock(); + documentViewController.Expect(dvc => dvc.UpdateToolTips()); + + IToolViewController toolViewController = mocks.Stub(); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()) + .Return(false) + .WhenCalled(invocation => invocation.ReturnValue = viewOpened); + toolViewController.Stub(tvc => tvc.OpenToolView(Arg.Is.TypeOf)) + .WhenCalled(invocation => projectExplorer = (ProjectExplorer)invocation.Arguments[0]); + toolViewController.Stub(tvc => tvc.CloseToolView(Arg.Is.TypeOf)); + mocks.ReplayAll(); + IEnumerable treeNodeInfos = new[] { new TreeNodeInfo @@ -258,28 +266,12 @@ } }; - ProjectExplorer projectExplorer = null; + var project = new Project(); - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - applicationSelection.Expect(a => a.SelectionChanged += null).IgnoreArguments(); - toolViewController.Expect(tvc => tvc.OpenToolView(Arg.Matches(v => true))).WhenCalled(m => - { - projectExplorer = (ProjectExplorer)m.Arguments[0]; - }); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - documentViewController.Expect(dvc => dvc.UpdateToolTips()); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - } - mocks.ReplayAll(); - - Project project = new Project(); - using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { controller.OpenView(); + viewOpened = true; // Call controller.Update(project); @@ -298,17 +290,14 @@ IDocumentViewController documentViewController = mocks.StrictMock(); IViewCommands viewCommands = mocks.StrictMock(); IApplicationSelection applicationSelection = mocks.StrictMock(); - IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); - - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false).Repeat.Twice(); - } + IToolViewController toolViewController = mocks.Stub(); + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()).Return(false); mocks.ReplayAll(); - Project project = new Project(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + var project = new Project(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { // Call @@ -322,24 +311,29 @@ public void Dispose_ViewActive_ViewClosed() { // Setup + var viewOpened = false; + var mocks = new MockRepository(); - IDocumentViewController documentViewController = mocks.StrictMock(); - IViewCommands viewCommands = mocks.StrictMock(); - IApplicationSelection applicationSelection = mocks.StrictMock(); + IDocumentViewController documentViewController = mocks.Stub(); + IViewCommands viewCommands = mocks.Stub(); + IApplicationSelection applicationSelection = mocks.Stub(); + applicationSelection.Stub(s => s.SelectionChanged += null).IgnoreArguments(); + applicationSelection.Stub(s => s.SelectionChanged -= null).IgnoreArguments(); IToolViewController toolViewController = mocks.StrictMock(); - IEnumerable treeNodeInfos = Enumerable.Empty(); - - using (mocks.Ordered()) - { - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - toolViewController.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - } - + toolViewController.Stub(tvc => tvc.IsToolWindowOpen()) + .Return(false) + .WhenCalled(invocation => invocation.ReturnValue = viewOpened); + toolViewController.Stub(tvc => tvc.OpenToolView(Arg.Is.TypeOf)); + toolViewController.Expect(tvc => tvc.CloseToolView(Arg.Is.TypeOf)); mocks.ReplayAll(); + IEnumerable treeNodeInfos = Enumerable.Empty(); + using (var controller = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos)) { + controller.OpenView(); + viewOpened = true; + // Call controller.Dispose(); }