Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs
===================================================================
diff -u -r4adf3910b91fba2fe6e7f7766836082046ab769a -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 4adf3910b91fba2fe6e7f7766836082046ab769a)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -202,7 +202,8 @@
/// Path to database file.
/// is invalid.
/// Thrown when:
- /// - does not exist
/// - the database does not contain the table version.
+ /// - does not exist
+ /// - the database does not contain the table version.
///
///
private void SetConnectionToFile(string databaseFilePath)
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r4adf3910b91fba2fe6e7f7766836082046ab769a -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4adf3910b91fba2fe6e7f7766836082046ab769a)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -43,10 +43,18 @@
..\..\..\..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll
True
+
+ ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Fluent.dll
+
+
+ ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Microsoft.Windows.Shell.dll
+
..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll
True
+
+
..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
True
@@ -62,6 +70,12 @@
..\..\..\..\packages\System.Data.SQLite.EF6.1.0.99.0\lib\net40\System.Data.SQLite.EF6.dll
True
+
+
+ ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\System.Windows.Interactivity.dll
+
+
+
@@ -81,6 +95,10 @@
{3bbfd65b-b277-4e50-ae6d-bd24c3434609}
Core.Common.Base
+
+ {30E4C2AE-719E-4D70-9FA9-668A9767FBFA}
+ Core.Common.Gui
+
{F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
Core.Common.Utils
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs
===================================================================
diff -u -r99a9ff7746c6c38cfe963c8702fd386b34f98701 -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 99a9ff7746c6c38cfe963c8702fd386b34f98701)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -1,8 +1,11 @@
using System;
using System.IO;
using Core.Common.Base.Data;
+using Core.Common.Gui;
+using Core.Common.Gui.Forms.MainWindow;
using Core.Common.TestUtil;
using NUnit.Framework;
+using Rhino.Mocks;
using Ringtoets.Integration.Data;
namespace Application.Ringtoets.Storage.Test.IntegrationTests
@@ -95,6 +98,93 @@
Assert.AreNotSame(project, loadedProject);
}
+ [Test]
+ [STAThread]
+ public void GivenRingtoetsGuiWithStorageSql_WhenRunWithValidFile_ProjectSet()
+ {
+ // Setup
+ var testFile = Path.Combine(testDataPath, "ValidRingtoetsDatabase.rtd");
+ var projectStore = new StorageSqLite();
+
+ using (var gui = new RingtoetsGui(new MainWindow(), projectStore))
+ {
+ // Call
+ Action action = () => gui.Run(testFile);
+
+ // Assert
+ var expectedMessages = new[]
+ {
+ "Openen van bestaand Ringtoetsproject.",
+ "Bestaand Ringtoetsproject succesvol geopend.",
+ };
+ TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 13);
+ Assert.AreEqual(testFile, gui.ProjectFilePath);
+ Assert.NotNull(gui.Project);
+ Assert.AreEqual("ValidRingtoetsDatabase", gui.Project.Name);
+ Assert.AreEqual("Test description", gui.Project.Description);
+ CollectionAssert.IsEmpty(gui.Project.Items);
+ }
+ }
+
+ [Test]
+ [STAThread]
+ public void GivenRingtoetsGuiWithStorageSql_WhenRunWithInvalidFile_EmptyProjectSet()
+ {
+ // Setup
+ var testFile = "SomeFile";
+ var projectStore = new StorageSqLite();
+
+ using (var gui = new RingtoetsGui(new MainWindow(), projectStore))
+ {
+ // Call
+ Action action = () => gui.Run(testFile);
+
+ // Assert
+ var expectedMessages = new[]
+ {
+ "Openen van bestaand Ringtoetsproject.",
+ string.Format("Fout bij het lezen van bestand '{0}': ", testFile),
+ "Het is niet gelukt om het Ringtoetsproject te laden.",
+ "Nieuw project aanmaken..."
+ };
+ TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 15);
+ Assert.AreEqual(null, gui.ProjectFilePath);
+ Assert.NotNull(gui.Project);
+ Assert.AreEqual("Project", gui.Project.Name);
+ Assert.IsEmpty(gui.Project.Description);
+ CollectionAssert.IsEmpty(gui.Project.Items);
+ }
+ }
+
+ [Test]
+ [STAThread]
+ [TestCase(null)]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void GivenRingtoetsGuiWithStorageSql_WhenRunWithEmptyFile_EmptyProjectSet(string testFile)
+ {
+ // Setup
+ var projectStore = new StorageSqLite();
+
+ using (var gui = new RingtoetsGui(new MainWindow(), projectStore))
+ {
+ // Call
+ Action action = () => gui.Run(testFile);
+
+ // Assert
+ var expectedMessages = new[]
+ {
+ "Nieuw project aanmaken..."
+ };
+ TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 12);
+ Assert.AreEqual(null, gui.ProjectFilePath);
+ Assert.NotNull(gui.Project);
+ Assert.AreEqual("Project", gui.Project.Name);
+ Assert.IsEmpty(gui.Project.Description);
+ CollectionAssert.IsEmpty(gui.Project.Items);
+ }
+ }
+
private void TearDownTempRingtoetsFile(string filePath)
{
GC.Collect();
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/packages.config
===================================================================
diff -u -r0155f2f233aefc7951782b302e1398e02c00f298 -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/packages.config (.../packages.config) (revision 0155f2f233aefc7951782b302e1398e02c00f298)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/packages.config (.../packages.config) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -1,6 +1,7 @@
+
Index: Core/Common/src/Core.Common.Gui/Commands/StorageCommandHandler.cs
===================================================================
diff -u -rbc173e2a73c395bf64d1d9b4ad8d81129a1cdd7c -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Core/Common/src/Core.Common.Gui/Commands/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision bc173e2a73c395bf64d1d9b4ad8d81129a1cdd7c)
+++ Core/Common/src/Core.Common.Gui/Commands/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -114,17 +114,7 @@
{
log.Info(Resources.Project_existing_opening_project);
- Project loadedProject;
- try
- {
- loadedProject = projectPersistor.LoadProject(filePath);
- }
- catch (StorageException e)
- {
- log.Error(e.Message, e.InnerException);
- log.Error(Resources.Project_existing_project_opening_failed);
- return false;
- }
+ var loadedProject = LoadProjectFromStorage(filePath);
if (loadedProject == null)
{
@@ -144,6 +134,32 @@
return true;
}
+ ///
+ /// Loads the project from the .
+ ///
+ /// The path to load a from.
+ /// The loaded from or null if the project
+ /// could not be loaded from .
+ private Project LoadProjectFromStorage(string filePath)
+ {
+ Project loadedProject = null;
+
+ try
+ {
+ loadedProject = projectPersistor.LoadProject(filePath);
+ }
+ catch (StorageException e)
+ {
+ log.Error(e.Message, e.InnerException);
+ }
+ catch (ArgumentException e)
+ {
+ log.Error(e.Message, e.InnerException);
+ }
+
+ return loadedProject;
+ }
+
public void CloseProject()
{
if (projectOwner.Project == null)
Index: Core/Common/src/Core.Common.Gui/RingtoetsGui.cs
===================================================================
diff -u -r5774b9c9fd8cc22fc2196ec871431631133e6221 -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b
--- Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 5774b9c9fd8cc22fc2196ec871431631133e6221)
+++ Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b)
@@ -141,17 +141,8 @@
log.Info(Resources.RingtoetsGui_Run_Starting_application);
- if (!string.IsNullOrEmpty(projectPath))
- {
- storageCommandHandler.OpenExistingProject(projectPath);
- }
- else
- {
- log.Info(Resources.RingtoetsGui_Run_Creating_new_project);
+ InitializeProjectFromPath(projectPath);
- Project = new Project();
- }
-
log.Info(Resources.RingtoetsGui_Run_Initializing_graphical_user_interface);
Initialize();
@@ -165,6 +156,20 @@
MessageWindowLogAppender.Instance.Enabled = true;
}
+ private void InitializeProjectFromPath(string projectPath)
+ {
+ var setDefaultProject = string.IsNullOrWhiteSpace(projectPath);
+ if (!setDefaultProject)
+ {
+ setDefaultProject = !storageCommandHandler.OpenExistingProject(projectPath);
+ }
+ if (setDefaultProject)
+ {
+ log.Info(Resources.RingtoetsGui_Run_Creating_new_project);
+ Project = new Project();
+ }
+ }
+
public void Exit()
{
if (isExiting)