Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs =================================================================== diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88) +++ Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -62,22 +62,6 @@ } /// - /// This method returns an enumeration of that support the . - /// - /// The target to get the enumeration of supported for. - /// The enumeration of supported . - public IEnumerable GetSupportedFileImporters(object target) - { - if (target == null) - { - return Enumerable.Empty(); - } - - return plugins.SelectMany(plugin => plugin.GetFileImporters()) - .Where(fileImporter => fileImporter.CanImportOn(target)); - } - - /// /// This method returns an enumeration of that support the . /// /// The source to get the enumeration of supported for. Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs =================================================================== diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88) +++ Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -30,15 +30,6 @@ public abstract class ApplicationPlugin { /// - /// This method returns an enumeration of . - /// - /// The enumeration of provided by the . - public virtual IEnumerable GetFileImporters() - { - yield break; - } - - /// /// This method returns an enumeration of . /// /// The enumeration of provided by the . Index: Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs =================================================================== diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5) +++ Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -20,13 +20,12 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; - using Core.Common.Base.IO; using Core.Common.Base.Plugin; using Core.Common.Gui.Properties; - using log4net; namespace Core.Common.Gui.Commands @@ -39,7 +38,7 @@ private static readonly ILog log = LogManager.GetLogger(typeof(ExportImportCommandHandler)); private readonly ApplicationCore applicationCore; - + private readonly IEnumerable fileImporters; private readonly GuiImportHandler importHandler; private readonly GuiExportHandler exportHandler; @@ -48,16 +47,18 @@ /// /// The parent window onto which dialogs should be shown. /// The host of all application plugins. - public ExportImportCommandHandler(IWin32Window dialogParent, ApplicationCore applicationCore) + /// An enumeration of . + public ExportImportCommandHandler(IWin32Window dialogParent, ApplicationCore applicationCore, IEnumerable fileImporters) { this.applicationCore = applicationCore; - importHandler = new GuiImportHandler(dialogParent, this.applicationCore); + this.fileImporters = fileImporters; + importHandler = new GuiImportHandler(dialogParent, this.fileImporters); exportHandler = new GuiExportHandler(dialogParent, this.applicationCore); } - public bool CanImportOn(object obj) + public bool CanImportOn(object target) { - return applicationCore.GetSupportedFileImporters(obj).Any(); + return fileImporters.Any(fileImporter => fileImporter.CanImportOn(target)); } public void ImportOn(object target, IFileImporter importer = null) Index: Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs =================================================================== diff -u -rfa493fef4f3f244664392c28896afb2052596898 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision fa493fef4f3f244664392c28896afb2052596898) +++ Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -19,16 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; - using Core.Common.Base.IO; -using Core.Common.Base.Plugin; using Core.Common.Base.Service; using Core.Common.Gui.Forms; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Properties; - using log4net; namespace Core.Common.Gui.Commands @@ -41,17 +39,17 @@ private static readonly ILog log = LogManager.GetLogger(typeof(GuiImportHandler)); private readonly IWin32Window dialogParent; - private readonly ApplicationCore applicationCore; + private readonly IEnumerable fileImporters; /// /// Initializes a new instance of the class. /// /// The parent window to show dialogs on top. - /// The application-plugins host. - public GuiImportHandler(IWin32Window dialogParent, ApplicationCore applicationCore) + /// An enumeration of . + public GuiImportHandler(IWin32Window dialogParent, IEnumerable fileImporters) { this.dialogParent = dialogParent; - this.applicationCore = applicationCore; + this.fileImporters = fileImporters; } /// @@ -78,8 +76,8 @@ private IFileImporter GetSupportedImporterForTargetType(object target) { - var importers = applicationCore.GetSupportedFileImporters(target).ToArray(); - if (importers.Length == 0) + var importers = fileImporters.Where(fileImporter => fileImporter.CanImportOn(target)).ToArray(); + if (!importers.Any()) { MessageBox.Show(Resources.GuiImportHandler_GetSupportedImporterForTargetType_No_importer_available_for_this_item, Resources.GuiImportHandler_GetSupportedImporterForTargetType_Error); Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -r276383b754de8eafea064dd780e118d922379d76 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 276383b754de8eafea064dd780e118d922379d76) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -122,7 +122,7 @@ viewCommandHandler = new ViewCommandHandler(this, this, this, this); storageCommandHandler = new StorageCommandHandler(projectStore, this, this, this, this, viewCommandHandler); - exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, ApplicationCore); + exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, ApplicationCore, Plugins.SelectMany(p => p.GetFileImporters())); projectCommandHandler = new ProjectCommandHandler(this, MainWindow, ApplicationCore, this, this); WindowsApplication.EnableVisualStyles(); @@ -462,6 +462,8 @@ InitializeGuiPlugins(); + + CopyDefaultViewsFromUserSettings(); //enable activation AFTER initialization @@ -867,7 +869,7 @@ private ApplicationFeatureCommandHandler applicationFeatureCommands; private readonly ViewCommandHandler viewCommandHandler; private readonly ProjectCommandHandler projectCommandHandler; - private readonly ExportImportCommandHandler exportImportCommandHandler; + private ExportImportCommandHandler exportImportCommandHandler; private StorageCommandHandler storageCommandHandler; public IApplicationFeatureCommands ApplicationCommands Index: Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs =================================================================== diff -u -r67980a5c3c5cb71c185278e849b123e7f92990eb -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision 67980a5c3c5cb71c185278e849b123e7f92990eb) +++ Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -22,7 +22,7 @@ using System; using System.Collections.Generic; using System.Linq; - +using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui.Forms; @@ -60,6 +60,15 @@ public virtual void Deactivate() {} /// + /// This method returns an enumeration of . + /// + /// The enumeration of provided by the . + public virtual IEnumerable GetFileImporters() + { + yield break; + } + + /// /// Returns all instances provided for data of this plugin. /// public virtual IEnumerable GetPropertyInfos() Index: Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs =================================================================== diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88) +++ Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -44,195 +44,6 @@ } [Test] - public void AddPlugin_SimpleApplicationPluginWithImporter_ShouldExposePluginDefinitions() - { - // Setup - var targetItem = new object(); - - var mocks = new MockRepository(); - - var fileImporter = mocks.Stub(); - fileImporter.Stub(i => i.CanImportOn(targetItem)).Return(true); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new[] - { - fileImporter - } - }; - - // Call - applicationCore.AddPlugin(applicationPlugin); - - // Assert - IFileImporter[] supportedFileImporters = applicationCore.GetSupportedFileImporters(targetItem).ToArray(); - Assert.AreEqual(1, supportedFileImporters.Length); - Assert.AreSame(fileImporter, supportedFileImporters[0]); - } - - [Test] - public void RemovePlugin_SimpleApplicationPluginWithImport_ShouldNoLongerExposePluginDefinitions() - { - // Setup - var targetItem = new object(); - - var mocks = new MockRepository(); - - var fileImporter = mocks.Stub(); - fileImporter.Stub(i => i.CanImportOn(targetItem)).Return(true); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new[] - { - fileImporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Preconditions - Assert.AreEqual(1, applicationCore.GetSupportedFileImporters(targetItem).Count()); - - // Call - applicationCore.RemovePlugin(applicationPlugin); - - // Assert - Assert.AreEqual(0, applicationCore.GetSupportedFileImporters(targetItem).Count()); - } - - [Test] - public void GetSupportedFileImporters_SimpleApplicationPluginWithImportersAdded_ShouldOnlyProvideSupportedImporters() - { - // Setup - var targetItem = new B(); - - var supportedFileImporter1 = new SimpleFileImporter(); - var supportedFileImporter2 = new SimpleFileImporter(); - var unsupportedFileImporter = new SimpleFileImporter(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new IFileImporter[] - { - supportedFileImporter1, - supportedFileImporter2, - unsupportedFileImporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Call - var supportedImporters = applicationCore.GetSupportedFileImporters(targetItem).ToArray(); - - // Assert - Assert.AreEqual(2, supportedImporters.Length); - Assert.AreSame(supportedFileImporter1, supportedImporters[0]); - Assert.AreSame(supportedFileImporter2, supportedImporters[1]); - } - - [Test] - public void GetSupportedFileImporters_SimpleApplicationPluginWithImportersAdded_ShouldProvideNoImportersWhenTargetEqualsNull() - { - // Setup - var mocks = new MockRepository(); - - var fileImporter = mocks.Stub(); - fileImporter.Stub(i => i.CanImportOn(Arg.Is.Anything)).Return(true); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new[] - { - fileImporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Assert - IEnumerable supportedImporters = applicationCore.GetSupportedFileImporters(null); - - // Assert - CollectionAssert.IsEmpty(supportedImporters); - } - - [Test] - public void GetSupportedFileImporters_ImporterCannotImportToTargetObject_ReturnEmpty() - { - // Setup - var targetObject = new object(); - var mocks = new MockRepository(); - - var fileImporter = mocks.Stub(); - fileImporter.Stub(i => i.CanImportOn(targetObject)).Return(false); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new[] - { - fileImporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Assert - IEnumerable supportedImporters = applicationCore.GetSupportedFileImporters(targetObject); - - // Assert - CollectionAssert.IsEmpty(supportedImporters); - } - - [Test] - public void GetSupportedFileImporters_ImporterCanImportToTargetObject_ReturnImporter() - { - // Setup - var targetObject = new object(); - var mocks = new MockRepository(); - - var fileImporter = mocks.Stub(); - fileImporter.Stub(i => i.CanImportOn(targetObject)).Return(true); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileImporters = new[] - { - fileImporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Assert - IEnumerable supportedImporters = applicationCore.GetSupportedFileImporters(targetObject); - - // Assert - CollectionAssert.AreEqual(new[] - { - fileImporter - }, supportedImporters); - } - - [Test] public void GetSupportedFileExporters_SimpleApplicationPluginWithExportersAdded_ShouldOnlyProvideSupportedExporters() { // Setup @@ -358,17 +169,10 @@ private class SimpleApplicationPlugin : ApplicationPlugin { - public IEnumerable FileImporters { private get; set; } - public IEnumerable FileExporters { private get; set; } public IEnumerable DataItemInfos { private get; set; } - public override IEnumerable GetFileImporters() - { - return FileImporters; - } - public override IEnumerable GetFileExporters() { return FileExporters; Index: Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs =================================================================== diff -u -r151bab16a7ebc1bffc0621ab56c6dc219db1e90f -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs (.../ApplicationPluginTest.cs) (revision 151bab16a7ebc1bffc0621ab56c6dc219db1e90f) +++ Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs (.../ApplicationPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -29,19 +29,6 @@ public class ApplicationPluginTest { [Test] - public void GetFileImporters_ReturnEmptyEnumerable() - { - // Setup - var applicationPlugin = new SimpleApplicationPlugin(); - - // Call - var importers = applicationPlugin.GetFileImporters().ToArray(); - - // Assert - CollectionAssert.IsEmpty(importers); - } - - [Test] public void GetFileExporters_ReturnEmptyEnumerable() { // Setup @@ -67,9 +54,6 @@ CollectionAssert.IsEmpty(importers); } - private class SimpleApplicationPlugin : ApplicationPlugin - { - - } + private class SimpleApplicationPlugin : ApplicationPlugin {} } } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs =================================================================== diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs (.../ExportImportCommandHandlerTest.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88) +++ Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs (.../ExportImportCommandHandlerTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Windows.Forms; using Core.Common.Base.IO; using Core.Common.Base.Plugin; @@ -37,11 +38,12 @@ // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub(); + var fileImporters = new List(); mocks.ReplayAll(); var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); // Call var isImportPossible = commandHandler.CanImportOn(new object()); @@ -61,20 +63,16 @@ var dialogParent = mocks.Stub(); var objectImporter = mocks.Stub(); objectImporter.Stub(i => i.CanImportOn(target)).Return(true); - - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileImporters()) - .Return(new[] - { - objectImporter - }); mocks.ReplayAll(); + var fileImporters = new List + { + objectImporter + }; + var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); - // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -88,25 +86,20 @@ { // Setup var target = new object(); - var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectImporter = mocks.Stub(); objectImporter.Stub(i => i.CanImportOn(target)).Return(false); - - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileImporters()) - .Return(new[] - { - objectImporter - }); mocks.ReplayAll(); + var fileImporters = new List + { + objectImporter + }; + var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); - // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -120,28 +113,22 @@ { // Setup var target = new object(); - var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectImporter1 = mocks.Stub(); objectImporter1.Stub(i => i.CanImportOn(target)).Return(false); var objectImporter2 = mocks.Stub(); objectImporter2.Stub(i => i.CanImportOn(target)).Return(true); - - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileImporters()) - .Return(new[] - { - objectImporter1, - objectImporter2 - }); mocks.ReplayAll(); + var fileImporters = new List + { + objectImporter1, objectImporter2 + }; + var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); - // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -155,28 +142,22 @@ { // Setup var target = new object(); - var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectImporter1 = mocks.Stub(); objectImporter1.Stub(i => i.CanImportOn(target)).Return(false); var objectImporter2 = mocks.Stub(); objectImporter2.Stub(i => i.CanImportOn(target)).Return(false); - - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileImporters()) - .Return(new[] - { - objectImporter1, - objectImporter2 - }); mocks.ReplayAll(); + var fileImporters = new List + { + objectImporter1, objectImporter2 + }; + var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); - // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -193,9 +174,11 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); + var fileImporters = new List(); + var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); // Call var isExportPossible = commandHandler.CanExportFrom(new object()); @@ -210,7 +193,7 @@ { // Setup var target = new object(); - + var fileImporters = new List(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectExporter = mocks.Stub(); @@ -228,7 +211,7 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(objectApplicationPluginMock); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); // Call var isExportPossible = commandHandler.CanExportFrom(new object()); @@ -243,7 +226,7 @@ { // Setup var target = new object(); - + var fileImporters = new List(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectExporter1 = mocks.Stub(); @@ -265,7 +248,7 @@ var applicationCore = new ApplicationCore(); applicationCore.AddPlugin(objectApplicationPluginMock); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore); + var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); // Call var isExportPossible = commandHandler.CanExportFrom(new object()); Index: Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs =================================================================== diff -u -r151bab16a7ebc1bffc0621ab56c6dc219db1e90f -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs (.../GuiPluginTest.cs) (revision 151bab16a7ebc1bffc0621ab56c6dc219db1e90f) +++ Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs (.../GuiPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -20,9 +20,7 @@ // All rights reserved. using Core.Common.Gui.Plugin; - using NUnit.Framework; - using Rhino.Mocks; namespace Core.Common.Gui.Test.Plugin @@ -69,8 +67,11 @@ var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call TestDelegate call = () => plugin.Activate(); @@ -88,8 +89,11 @@ var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call TestDelegate call = () => plugin.Deactivate(); @@ -100,15 +104,18 @@ } [Test] - public void GetPropertyInfos_ReturnEmpty() + public void GetPropertyInfos_ReturnsEmpty() { // Setup var mocks = new MockRepository(); var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call var infos = plugin.GetPropertyInfos(); @@ -119,15 +126,18 @@ } [Test] - public void GetViewInfos_ReturnEmpty() + public void GetViewInfos_ReturnsEmpty() { // Setup var mocks = new MockRepository(); var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call var infos = plugin.GetViewInfos(); @@ -138,15 +148,18 @@ } [Test] - public void GetTreeNodeInfos_ReturnEmpty() + public void GetTreeNodeInfos_ReturnsEmpty() { // Setup var mocks = new MockRepository(); var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call var infos = plugin.GetTreeNodeInfos(); @@ -157,15 +170,18 @@ } [Test] - public void GetChildDataWithViewDefinitions_ReturnEmpty() + public void GetChildDataWithViewDefinitions_ReturnsEmpty() { // Setup var mocks = new MockRepository(); var gui = mocks.StrictMock(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call var infos = plugin.GetChildDataWithViewDefinitions(null); @@ -176,15 +192,40 @@ } [Test] + public void GetFileImporters_ReturnsEmpty() + { + // Setup + var mocks = new MockRepository(); + var gui = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var plugin = new SimpleGuiPlugin + { + Gui = gui + }) + { + // Call + var infos = plugin.GetFileImporters(); + + // Assert + CollectionAssert.IsEmpty(infos); + } + mocks.VerifyAll(); + } + + [Test] public void Dispose_SetGuiToNull() { // Setup var mocks = new MockRepository(); var gui = mocks.Stub(); mocks.ReplayAll(); - using (var plugin = new SimpleGuiPlugin { Gui = gui }) + using (var plugin = new SimpleGuiPlugin { + Gui = gui + }) + { // Call plugin.Dispose(); @@ -194,9 +235,6 @@ mocks.VerifyAll(); } - private class SimpleGuiPlugin : GuiPlugin - { - - } + private class SimpleGuiPlugin : GuiPlugin {} } } \ No newline at end of file Index: Core/Common/test/Core.Common.Integration.Test/Ringtoets/Application.Ringtoets/GuiImportHandlerTest.cs =================================================================== diff -u -r151bab16a7ebc1bffc0621ab56c6dc219db1e90f -raf42240385db3d3f04bca830513c7464e6f74668 --- Core/Common/test/Core.Common.Integration.Test/Ringtoets/Application.Ringtoets/GuiImportHandlerTest.cs (.../GuiImportHandlerTest.cs) (revision 151bab16a7ebc1bffc0621ab56c6dc219db1e90f) +++ Core/Common/test/Core.Common.Integration.Test/Ringtoets/Application.Ringtoets/GuiImportHandlerTest.cs (.../GuiImportHandlerTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -20,7 +20,8 @@ // All rights reserved. using System; -using Core.Common.Base.Plugin; +using System.Collections.Generic; +using Core.Common.Base.IO; using Core.Common.Gui.Commands; using Core.Common.Gui.Forms.MainWindow; using NUnit.Extensions.Forms; @@ -33,11 +34,10 @@ public class GuiImportHandlerTest : NUnitFormTest { [Test] - public void NoImporterAvailableGivesMessageBox() + public void Constructor_NoImporterAvailable_GivesMessageBox() { // Setup - var applicationCore = new ApplicationCore(); - + var fileImporters = new List(); var mocks = new MockRepository(); var mainWindow = mocks.Stub(); mocks.ReplayAll(); @@ -53,7 +53,7 @@ messageBox.ClickOk(); }; - var importHandler = new GuiImportHandler(mainWindow, applicationCore); + var importHandler = new GuiImportHandler(mainWindow, fileImporters); // Call importHandler.ImportDataTo(typeof(Int64)); Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsApplicationPlugin.cs =================================================================== diff -u -r8b9903ce9a5e5b860ee8ba6719737783be7a8cab -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsApplicationPlugin.cs (.../GrassCoverErosionInwardsApplicationPlugin.cs) (revision 8b9903ce9a5e5b860ee8ba6719737783be7a8cab) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsApplicationPlugin.cs (.../GrassCoverErosionInwardsApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -19,21 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; -using Core.Common.Base.IO; using Core.Common.Base.Plugin; -using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporter; namespace Ringtoets.GrassCoverErosionInwards.Plugin { /// /// The application plugin for the GEKB failure mechanism. /// - public class GrassCoverErosionInwardsApplicationPlugin : ApplicationPlugin - { - public override IEnumerable GetFileImporters() - { - yield return new DikeProfilesImporter(); - } - } + public class GrassCoverErosionInwardsApplicationPlugin : ApplicationPlugin {} } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs =================================================================== diff -u -r766487194eab00bc9205f5cd29f269c9af5f2ab8 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs (.../GrassCoverErosionInwardsGuiPlugin.cs) (revision 766487194eab00bc9205f5cd29f269c9af5f2ab8) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs (.../GrassCoverErosionInwardsGuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -25,6 +25,7 @@ using System.IO; using System.Linq; using System.Windows.Forms; +using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; @@ -35,13 +36,13 @@ using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; -using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; using Ringtoets.GrassCoverErosionInwards.Forms.Views; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporter; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.HydraRing.IO; using GrassCoverErosionInwardsDataResources = Ringtoets.GrassCoverErosionInwards.Data.Properties.Resources; @@ -101,6 +102,11 @@ }; } + public override IEnumerable GetFileImporters() + { + yield return new DikeProfilesImporter(); + } + public override IEnumerable GetTreeNodeInfos() { yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo( Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsApplicationPluginTest.cs =================================================================== diff -u -r68588fbca4cc848bf72e39ec16940ce96c596bde -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsApplicationPluginTest.cs (.../GrassCoverErosionInwardsApplicationPluginTest.cs) (revision 68588fbca4cc848bf72e39ec16940ce96c596bde) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsApplicationPluginTest.cs (.../GrassCoverErosionInwardsApplicationPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -18,18 +18,6 @@ Assert.IsInstanceOf(applicationPlugin); } - [Test] - public void GetFileImporters_Always_ReturnExpectedFileImporter() - { - // Setup - var plugin = new GrassCoverErosionInwardsApplicationPlugin(); - - // Call - var importers = plugin.GetFileImporters().ToArray(); - - // Assert - Assert.AreEqual(1, importers.Length); - Assert.IsInstanceOf(importers[0]); - } + } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsGuiPluginTest.cs =================================================================== diff -u -rdf02e9274a94d8763da204833a4d93f984e242c6 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsGuiPluginTest.cs (.../GrassCoverErosionInwardsGuiPluginTest.cs) (revision df02e9274a94d8763da204833a4d93f984e242c6) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsGuiPluginTest.cs (.../GrassCoverErosionInwardsGuiPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -33,6 +33,7 @@ using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; using Ringtoets.GrassCoverErosionInwards.Forms.Views; +using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporter; namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test { @@ -159,5 +160,33 @@ Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(GrassCoverErosionInwardsScenariosView))); } } + + [Test] + public void GetFileImporters_Always_ReturnsExpectedFileImporter() + { + // Setup + var mocks = new MockRepository(); + var applicationCore = new ApplicationCore(); + + var guiStub = mocks.Stub(); + guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); + + guiStub.Stub(g => g.ApplicationCore).Return(applicationCore); + + mocks.ReplayAll(); + + using (var guiPlugin = new GrassCoverErosionInwardsGuiPlugin + { + Gui = guiStub + }) + { + // Call + var importers = guiPlugin.GetFileImporters().ToArray(); + + // Assert + Assert.AreEqual(1, importers.Length); + Assert.IsInstanceOf(importers[0]); + } + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs =================================================================== diff -u -r64d5609bb2912cd52dc74deffdd189222e240599 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision 64d5609bb2912cd52dc74deffdd189222e240599) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -22,14 +22,10 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; -using Core.Common.Base.IO; using Core.Common.Base.Plugin; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Forms.Helpers; -using Ringtoets.Common.IO; using Ringtoets.Integration.Data; -using Ringtoets.Integration.Plugin.FileImporters; - using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; @@ -57,12 +53,6 @@ }; } - public override IEnumerable GetFileImporters() - { - yield return new ReferenceLineImporter(); - yield return new FailureMechanismSectionsImporter(); - } - private static string GetUniqueForAssessmentSectionName(Project project, string baseName) { return NamingHelper.GetUniqueName(project.Items.OfType(), baseName, a => a.Name); Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -rdf02e9274a94d8763da204833a4d93f984e242c6 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision df02e9274a94d8763da204833a4d93f984e242c6) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -26,6 +26,7 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base.Data; +using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Common.Gui; @@ -45,6 +46,7 @@ using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.Common.Forms.Views; +using Ringtoets.Common.IO; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.HeightStructures.Data; @@ -308,6 +310,12 @@ }; } + public override IEnumerable GetFileImporters() + { + yield return new ReferenceLineImporter(); + yield return new FailureMechanismSectionsImporter(); + } + /// /// Gets the child data instances that have definitions of some parent data object. /// Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs =================================================================== diff -u -r64d5609bb2912cd52dc74deffdd189222e240599 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision 64d5609bb2912cd52dc74deffdd189222e240599) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -1,14 +1,31 @@ -using System.Linq; +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU 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 General Public License for more details. +// +// You should have received a copy of the GNU 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.Linq; using Core.Common.Base.Data; -using Core.Common.Base.IO; using Core.Common.Base.Plugin; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.IO; using Ringtoets.Integration.Data; -using Ringtoets.Integration.Plugin.FileImporters; - using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; namespace Ringtoets.Integration.Plugin.Test @@ -47,21 +64,6 @@ } [Test] - public void GetFileImporters_ReturnsExpectedFileImporters() - { - // Setup - var plugin = new RingtoetsApplicationPlugin(); - - // Call - IFileImporter[] importers = plugin.GetFileImporters().ToArray(); - - // Assert - Assert.AreEqual(2, importers.Length); - Assert.AreEqual(1, importers.Count(i => i is ReferenceLineImporter)); - Assert.AreEqual(1, importers.Count(i => i is FailureMechanismSectionsImporter)); - } - - [Test] public void WhenAddingAssessmentSection_GivenProjectHasAssessmentSection_ThenAddedAssessmentSectionHasUniqueName() { // Setup Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs =================================================================== diff -u -rdf02e9274a94d8763da204833a4d93f984e242c6 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision df02e9274a94d8763da204833a4d93f984e242c6) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -25,6 +25,7 @@ using System.Linq; using System.Windows.Threading; using Core.Common.Base.Data; +using Core.Common.Base.IO; using Core.Common.Base.Plugin; using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; @@ -44,13 +45,15 @@ using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.Views; +using Ringtoets.Common.IO; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; using Ringtoets.Integration.Forms.Views.SectionResultViews; +using Ringtoets.Integration.Plugin.FileImporters; using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -82,16 +85,18 @@ mocks.ReplayAll(); using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) - using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - ringtoetsGuiPlugin.Gui = gui; - gui.Run(); + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); - // Call - Action action = () => gui.Project = new Project(); + // Call + Action action = () => gui.Project = new Project(); - // Assert - TestHelper.AssertLogMessagesCount(action, 0); + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } } Dispatcher.CurrentDispatcher.InvokeShutdown(); @@ -110,29 +115,28 @@ var testDataPath = Path.Combine(testDataDir, "complete.sqlite"); using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) - using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - ringtoetsGuiPlugin.Gui = gui; - gui.Run(); - - var project = new Project(); - IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + var project = new Project(); + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) { - FilePath = testDataPath - } - }; - project.Items.Add(section); + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = testDataPath + } + }; + project.Items.Add(section); - // Call - Action action = () => - { - gui.Project = project; - }; + // Call + Action action = () => { gui.Project = project; }; - // Assert - TestHelper.AssertLogMessagesCount(action, 0); + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } } Dispatcher.CurrentDispatcher.InvokeShutdown(); @@ -148,35 +152,34 @@ mocks.ReplayAll(); using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) - using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - var project = new Project(); - var notExistingFile = "not_existing_file"; - - IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + var project = new Project(); + var notExistingFile = "not_existing_file"; + + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) { - FilePath = notExistingFile - } - }; - project.Items.Add(section); + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = notExistingFile + } + }; + project.Items.Add(section); - ringtoetsGuiPlugin.Gui = gui; - gui.Run(); + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); - // Call - Action action = () => - { - gui.Project = project; - }; + // Call + Action action = () => { gui.Project = project; }; - // Assert - var fileMissingMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", notExistingFile); - string message = string.Format( - RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, - fileMissingMessage); - TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(message, LogLevelConstant.Warn)); + // Assert + var fileMissingMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", notExistingFile); + string message = string.Format( + RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, + fileMissingMessage); + TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(message, LogLevelConstant.Warn)); + } } Dispatcher.CurrentDispatcher.InvokeShutdown(); @@ -417,5 +420,20 @@ // Assert CollectionAssert.IsEmpty(childrenWithViewDefinitions); } + + [Test] + public void GetFileImporters_ReturnsExpectedFileImporters() + { + // Setup + var plugin = new RingtoetsGuiPlugin(); + + // Call + IFileImporter[] importers = plugin.GetFileImporters().ToArray(); + + // Assert + Assert.AreEqual(2, importers.Length); + Assert.AreEqual(1, importers.Count(i => i is ReferenceLineImporter)); + Assert.AreEqual(1, importers.Count(i => i is FailureMechanismSectionsImporter)); + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingApplicationPlugin.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingApplicationPlugin.cs (.../PipingApplicationPlugin.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingApplicationPlugin.cs (.../PipingApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -19,22 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; -using Core.Common.Base.IO; using Core.Common.Base.Plugin; -using Ringtoets.Piping.Plugin.FileImporter; namespace Ringtoets.Piping.Plugin { /// /// The application plugin for the piping failure mechanism. /// - public class PipingApplicationPlugin : ApplicationPlugin - { - public override IEnumerable GetFileImporters() - { - yield return new PipingSurfaceLinesCsvImporter(); - yield return new PipingSoilProfilesImporter(); - } - } + public class PipingApplicationPlugin : ApplicationPlugin {} } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs =================================================================== diff -u -r91129a62863d9c89359649c3bc59f76b220ab34b -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision 91129a62863d9c89359649c3bc59f76b220ab34b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -24,6 +24,7 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base.IO; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; @@ -40,6 +41,7 @@ using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using Ringtoets.Piping.Forms.Views; +using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; using Ringtoets.Piping.Service; using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources; @@ -73,6 +75,12 @@ yield return new PropertyInfo(); } + public override IEnumerable GetFileImporters() + { + yield return new PipingSurfaceLinesCsvImporter(); + yield return new PipingSoilProfilesImporter(); + } + public override IEnumerable GetViewInfos() { yield return new ViewInfo @@ -125,10 +133,7 @@ Image = RingtoetsCommonFormsResources.ScenariosIcon, AdditionalDataCheck = context => context.WrappedData == context.ParentFailureMechanism.CalculationsGroup, CloseForData = ClosePipingScenariosViewForData, - AfterCreate = (view, context) => - { - view.PipingFailureMechanism = context.ParentFailureMechanism; - } + AfterCreate = (view, context) => { view.PipingFailureMechanism = context.ParentFailureMechanism; } }; } @@ -400,6 +405,46 @@ #endregion + private void CalculateAll(PipingFailureMechanismContext failureMechanismContext) + { + var calculations = GetAllPipingCalculations(failureMechanismContext.WrappedData); + var assessmentInput = failureMechanismContext.WrappedData.PipingProbabilityAssessmentInput; + var norm = failureMechanismContext.Parent.FailureMechanismContribution.Norm; + var contribution = failureMechanismContext.WrappedData.Contribution; + + CalculateAll(calculations, assessmentInput, norm, contribution); + } + + private void CalculateAll(CalculationGroup group, PipingCalculationGroupContext context) + { + var calculations = group.GetCalculations().OfType().ToArray(); + var assessmentInput = context.FailureMechanism.PipingProbabilityAssessmentInput; + var norm = context.AssessmentSection.FailureMechanismContribution.Norm; + var contribution = context.FailureMechanism.Contribution; + + CalculateAll(calculations, assessmentInput, norm, contribution); + } + + private static void ValidateAll(IEnumerable pipingCalculations) + { + foreach (PipingCalculation calculation in pipingCalculations) + { + PipingCalculationService.Validate(calculation); + } + } + + private void CalculateAll(IEnumerable calculations, PipingProbabilityAssessmentInput assessmentInput, int norm, double contribution) + { + ActivityProgressDialogRunner.Run( + Gui.MainWindow, + calculations + .Select(pc => new PipingCalculationActivity(pc, + assessmentInput, + norm, + contribution)) + .ToList()); + } + # region Piping TreeNodeInfo private ContextMenuStrip FailureMechanismEnabledContextMenuStrip(PipingFailureMechanismContext pipingFailureMechanismContext, object parentData, TreeViewControl treeViewControl) @@ -411,8 +456,8 @@ .AddToggleRelevancyOfFailureMechanismItem(pipingFailureMechanismContext, RemoveAllViewsForItem) .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem( - pipingFailureMechanismContext, - fm => ValidateAll(fm.WrappedData.Calculations.OfType())) + pipingFailureMechanismContext, + fm => ValidateAll(fm.WrappedData.Calculations.OfType())) .AddPerformAllCalculationsInFailureMechanismItem(pipingFailureMechanismContext, CalculateAll) .AddClearAllCalculationOutputInFailureMechanismItem(pipingFailureMechanismContext.WrappedData) .AddSeparator() @@ -425,7 +470,7 @@ .AddPropertiesItem() .Build(); } - + private void RemoveAllViewsForItem(PipingFailureMechanismContext failureMechanismContext) { Gui.ViewCommands.RemoveAllViewsForItem(failureMechanismContext); @@ -654,9 +699,9 @@ { bool surfaceLineAvailable = nodeData.AvailablePipingSurfaceLines.Any() && nodeData.AvailableStochasticSoilModels.Any(); - string pipingCalculationGroupGeneratePipingCalculationsToolTip = surfaceLineAvailable - ? PipingFormsResources.PipingCalculationGroup_Generate_PipingCalculations_ToolTip - : PipingFormsResources.PipingCalculationGroup_Generate_PipingCalculations_NoSurfaceLinesOrSoilModels_ToolTip; + string pipingCalculationGroupGeneratePipingCalculationsToolTip = surfaceLineAvailable + ? PipingFormsResources.PipingCalculationGroup_Generate_PipingCalculations_ToolTip + : PipingFormsResources.PipingCalculationGroup_Generate_PipingCalculations_NoSurfaceLinesOrSoilModels_ToolTip; var generateCalculationsItem = new StrictContextMenuItem( RingtoetsCommonFormsResources.CalculationGroup_Generate_Scenarios, @@ -696,45 +741,5 @@ } #endregion - - private void CalculateAll(PipingFailureMechanismContext failureMechanismContext) - { - var calculations = GetAllPipingCalculations(failureMechanismContext.WrappedData); - var assessmentInput = failureMechanismContext.WrappedData.PipingProbabilityAssessmentInput; - var norm = failureMechanismContext.Parent.FailureMechanismContribution.Norm; - var contribution = failureMechanismContext.WrappedData.Contribution; - - CalculateAll(calculations, assessmentInput, norm, contribution); - } - - private void CalculateAll(CalculationGroup group, PipingCalculationGroupContext context) - { - var calculations = group.GetCalculations().OfType().ToArray(); - var assessmentInput = context.FailureMechanism.PipingProbabilityAssessmentInput; - var norm = context.AssessmentSection.FailureMechanismContribution.Norm; - var contribution = context.FailureMechanism.Contribution; - - CalculateAll(calculations, assessmentInput, norm, contribution); - } - - private static void ValidateAll(IEnumerable pipingCalculations) - { - foreach (PipingCalculation calculation in pipingCalculations) - { - PipingCalculationService.Validate(calculation); - } - } - - private void CalculateAll(IEnumerable calculations, PipingProbabilityAssessmentInput assessmentInput, int norm, double contribution) - { - ActivityProgressDialogRunner.Run( - Gui.MainWindow, - calculations - .Select(pc => new PipingCalculationActivity(pc, - assessmentInput, - norm, - contribution)) - .ToList()); - } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingApplicationPluginTest.cs =================================================================== diff -u -r0bfd1f4e2a179c8575045e5af70dce2930665626 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingApplicationPluginTest.cs (.../PipingApplicationPluginTest.cs) (revision 0bfd1f4e2a179c8575045e5af70dce2930665626) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingApplicationPluginTest.cs (.../PipingApplicationPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -1,7 +1,5 @@ -using System.Linq; -using Core.Common.Base.Plugin; +using Core.Common.Base.Plugin; using NUnit.Framework; -using Ringtoets.Piping.Plugin.FileImporter; namespace Ringtoets.Piping.Plugin.Test { @@ -17,20 +15,5 @@ // assert Assert.IsInstanceOf(pipingApplicationPlugin); } - - [Test] - public void GetFileImporters_Always_ReturnExpectedFileImporters() - { - // Setup - var plugin = new PipingApplicationPlugin(); - - // Call - var importers = plugin.GetFileImporters().ToArray(); - - // Assert - Assert.AreEqual(2, importers.Length); - Assert.IsInstanceOf(importers[0]); - Assert.IsInstanceOf(importers[1]); - } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs =================================================================== diff -u -r4af0bffb50faa15fa8accb67e35b80af45dc1213 -raf42240385db3d3f04bca830513c7464e6f74668 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs (.../PipingGuiPluginTest.cs) (revision 4af0bffb50faa15fa8accb67e35b80af45dc1213) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs (.../PipingGuiPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) @@ -33,6 +33,7 @@ using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using Ringtoets.Piping.Forms.Views; +using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; using GuiPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; @@ -183,5 +184,34 @@ Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(PipingScenariosView))); } } + + [Test] + public void GetFileImporters_Always_ReturnsExpectedFileImporters() + { + // Setup + var mocks = new MockRepository(); + var applicationCore = new ApplicationCore(); + + var guiStub = mocks.Stub(); + guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); + + guiStub.Stub(g => g.ApplicationCore).Return(applicationCore); + + mocks.ReplayAll(); + + using (var guiPlugin = new PipingGuiPlugin + { + Gui = guiStub + }) + { + // Call + var importers = guiPlugin.GetFileImporters().ToArray(); + + // Assert + Assert.AreEqual(2, importers.Length); + Assert.IsInstanceOf(importers[0]); + Assert.IsInstanceOf(importers[1]); + } + } } } \ No newline at end of file