Index: Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs =================================================================== diff -u -rc063a97260cc4d630a453c359d49fca96ed8ac80 -r761d4c23b5c98c87caa9a94d14b41074c862c425 --- Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision c063a97260cc4d630a453c359d49fca96ed8ac80) +++ Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -34,6 +34,7 @@ using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.MessageWindow; +using Core.Common.Gui.Forms.ProjectExplorer; using Core.Common.Gui.Forms.PropertyGridView; using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; @@ -417,6 +418,7 @@ { using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); // Precondition: @@ -454,6 +456,7 @@ using (var toolView = new TestView()) using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddToolView(toolView, ToolViewLocation.Left); @@ -483,6 +486,7 @@ using (var documentView = new TestView()) using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(documentView); @@ -518,6 +522,8 @@ { using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); + // Call gui.Run(); @@ -566,6 +572,8 @@ { using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); + // Call gui.Run(); @@ -615,6 +623,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call void Call() => gui.Run(testFile); @@ -669,6 +679,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call gui.Run(testFile); @@ -714,6 +726,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call void Call() => gui.Run(testFile); @@ -764,6 +778,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call void Call() => gui.Run(testFile); @@ -815,6 +831,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call void Call() => gui.Run(testFile); @@ -862,6 +880,8 @@ using (var mainWindow = new MainWindow()) using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) { + gui.Plugins.Add(new TestPlugin()); + // Call gui.Run(path); @@ -882,18 +902,13 @@ var mocks = new MockRepository(); var projectStore = mocks.Stub(); var projectMigrator = mocks.Stub(); - var plugin = mocks.Stub(); - plugin.Stub(p => p.Deactivate()); - plugin.Stub(p => p.Dispose()); - plugin.Expect(p => p.Activate()); - plugin.Expect(p => p.GetViewInfos()).Return(Enumerable.Empty()); - plugin.Expect(p => p.GetPropertyInfos()).Return(Enumerable.Empty()); IProjectFactory projectFactory = CreateProjectFactory(mocks); mocks.ReplayAll(); // Setup using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + var plugin = new TestPlugin(); gui.Plugins.Add(plugin); // Call @@ -916,6 +931,10 @@ var plugin = mocks.Stub(); plugin.Stub(p => p.GetViewInfos()).Return(Enumerable.Empty()); plugin.Stub(p => p.GetPropertyInfos()).Return(Enumerable.Empty()); + plugin.Stub(p => p.GetTreeNodeInfos()).Return(new TreeNodeInfo[] + { + new TreeNodeInfo() + }); plugin.Stub(p => p.Activate()).Throw(new Exception("ERROR!")); plugin.Expect(p => p.Deactivate()); plugin.Expect(p => p.Dispose()); @@ -945,6 +964,10 @@ var plugin = mocks.Stub(); plugin.Stub(p => p.GetViewInfos()).Return(Enumerable.Empty()); plugin.Stub(p => p.GetPropertyInfos()).Return(Enumerable.Empty()); + plugin.Stub(p => p.GetTreeNodeInfos()).Return(new TreeNodeInfo[] + { + new TreeNodeInfo() + }); plugin.Stub(p => p.Activate()).Throw(new Exception("ERROR!")); plugin.Stub(p => p.Deactivate()).Throw(new Exception("MORE ERROR!")); plugin.Expect(p => p.Dispose()); @@ -981,14 +1004,17 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); + // Call gui.Run(); // Assert CollectionAssert.IsEmpty(gui.ViewHost.DocumentViews); Assert.IsNull(gui.ViewHost.ActiveDocumentView); - Assert.AreEqual(2, gui.ViewHost.ToolViews.Count()); + Assert.AreEqual(3, gui.ViewHost.ToolViews.Count()); + Assert.AreEqual(1, gui.ViewHost.ToolViews.Count(v => v is ProjectExplorer)); Assert.AreEqual(1, gui.ViewHost.ToolViews.Count(v => v is PropertyGridView)); Assert.AreEqual(1, gui.ViewHost.ToolViews.Count(v => v is MessageWindow)); @@ -1253,6 +1279,7 @@ using (var treeView = new TreeViewControl()) using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); // Call @@ -1330,6 +1357,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); @@ -1361,6 +1389,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); @@ -1391,6 +1420,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); @@ -1423,6 +1453,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); @@ -1457,6 +1488,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(testView); @@ -1488,6 +1520,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(testView); @@ -1518,6 +1551,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); @@ -1550,6 +1584,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); Index: Core/Common/test/Core.Common.Integration.Test/Riskeer/Application.Riskeer/GuiCoreIntegrationTest.cs =================================================================== diff -u -r4b9e28a28b8004dc9dfca896c32e2a21c10a2405 -r761d4c23b5c98c87caa9a94d14b41074c862c425 --- Core/Common/test/Core.Common.Integration.Test/Riskeer/Application.Riskeer/GuiCoreIntegrationTest.cs (.../GuiCoreIntegrationTest.cs) (revision 4b9e28a28b8004dc9dfca896c32e2a21c10a2405) +++ Core/Common/test/Core.Common.Integration.Test/Riskeer/Application.Riskeer/GuiCoreIntegrationTest.cs (.../GuiCoreIntegrationTest.cs) (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Threading; using System.Windows.Controls; using System.Windows.Threading; @@ -30,6 +31,7 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Riskeer.Integration.Data; using Riskeer.Integration.Plugin; namespace Core.Common.Integration.Test.Riskeer.Application.Riskeer @@ -57,7 +59,7 @@ var projectStore = mocks.Stub(); var projectMigrator = mocks.Stub(); var projectFactory = mocks.Stub(); - projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(new RiskeerProject()); mocks.ReplayAll(); using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) @@ -73,35 +75,38 @@ [Apartment(ApartmentState.STA)] public void Run_StartWithCommonPlugins_RunsFasterThanThreshold() { - TestHelper.AssertIsFasterThan(7500, StartWithCommonPlugins); - } - - [Test] - [Apartment(ApartmentState.STA)] - public void FormActionIsRunForMainWindow() - { - //testing testhelper + visible changed event of mainwindow. - //could be tested separately but the combination is vital to many tests. That's why this test is here. + // Setup var mocks = new MockRepository(); var projectStore = mocks.Stub(); var projectMigrator = mocks.Stub(); var projectFactory = mocks.Stub(); - projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(new RiskeerProject()); mocks.ReplayAll(); using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { - gui.Run(); - var callCount = 0; - WpfTestHelper.ShowModal((Control) gui.MainWindow, () => callCount++); - Assert.AreEqual(1, callCount); + gui.Plugins.Add(new RiskeerPlugin()); + + // Call + void Action() + { + gui.Run(); + WpfTestHelper.ShowModal((Control) gui.MainWindow); + } + + // Assert + TestHelper.AssertIsFasterThan(7500, Action); } mocks.VerifyAll(); } - private static void StartWithCommonPlugins() + [Test] + [Apartment(ApartmentState.STA)] + public void FormActionIsRunForMainWindow() { + //testing testhelper + visible changed event of mainwindow. + //could be tested separately but the combination is vital to many tests. That's why this test is here. var mocks = new MockRepository(); var projectStore = mocks.Stub(); var projectMigrator = mocks.Stub(); @@ -111,11 +116,12 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { - gui.Plugins.Add(new RiskeerPlugin()); - + gui.Plugins.Add(new TestPlugin()); gui.Run(); - - WpfTestHelper.ShowModal((Control) gui.MainWindow); + + var callCount = 0; + WpfTestHelper.ShowModal((Control) gui.MainWindow, () => callCount++); + Assert.AreEqual(1, callCount); } mocks.VerifyAll(); Index: Core/Common/test/Core.Common.TestUtil/TestPlugin.cs =================================================================== diff -u --- Core/Common/test/Core.Common.TestUtil/TestPlugin.cs (revision 0) +++ Core/Common/test/Core.Common.TestUtil/TestPlugin.cs (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -0,0 +1,39 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using Core.Common.Base.Data; +using Core.Common.Controls.TreeView; +using Core.Common.Gui.Plugin; + +namespace Core.Common.TestUtil +{ + /// + /// Simple plugin that can be used in tests. + /// + public class TestPlugin : PluginBase + { + public override IEnumerable GetTreeNodeInfos() + { + yield return new TreeNodeInfo(); + } + } +} \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs =================================================================== diff -u -r1b53b144acc8a3a2826b63f0d841e4c123a8b461 -r761d4c23b5c98c87caa9a94d14b41074c862c425 --- Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision 1b53b144acc8a3a2826b63f0d841e4c123a8b461) +++ Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -31,6 +31,7 @@ using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.Gui.TestUtil; +using Core.Common.TestUtil; using Core.Common.Util.Reflection; using Core.Components.Chart.Data; using Core.Components.Chart.Forms; @@ -172,6 +173,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -212,6 +214,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -256,6 +259,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -298,6 +302,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); Index: Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs =================================================================== diff -u -r1b53b144acc8a3a2826b63f0d841e4c123a8b461 -r761d4c23b5c98c87caa9a94d14b41074c862c425 --- Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision 1b53b144acc8a3a2826b63f0d841e4c123a8b461) +++ Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -31,6 +31,7 @@ using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.Gui.TestUtil; +using Core.Common.TestUtil; using Core.Common.Util.Reflection; using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Forms; @@ -176,6 +177,7 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(new MapPlugin { Gui = gui @@ -219,6 +221,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -259,6 +262,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -303,6 +307,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); @@ -345,6 +350,7 @@ Gui = gui }; + gui.Plugins.Add(new TestPlugin()); gui.Plugins.Add(plugin); gui.Run(); Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -rda1df87d94dcc61aa26d5f033c6bf579c2249cdd -r761d4c23b5c98c87caa9a94d14b41074c862c425 --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision da1df87d94dcc61aa26d5f033c6bf579c2249cdd) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 761d4c23b5c98c87caa9a94d14b41074c862c425) @@ -181,6 +181,8 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(), new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); + // When gui.Run(testFile); @@ -218,6 +220,8 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(), new GuiCoreSettings())) { + gui.Plugins.Add(new TestPlugin()); + // When void Action() => gui.Run(projectFilePath);