Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Application.Ringtoets.MigrationConsole.csproj
===================================================================
diff -u -r0930763dbd895350070e8075dc9d7ba1bd89cf0f -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Application.Ringtoets.MigrationConsole.csproj (.../Application.Ringtoets.MigrationConsole.csproj) (revision 0930763dbd895350070e8075dc9d7ba1bd89cf0f)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Application.Ringtoets.MigrationConsole.csproj (.../Application.Ringtoets.MigrationConsole.csproj) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -45,6 +45,7 @@
True
Resources.resx
+
Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.Designer.cs
===================================================================
diff -u -r0930763dbd895350070e8075dc9d7ba1bd89cf0f -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 0930763dbd895350070e8075dc9d7ba1bd89cf0f)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -82,15 +82,6 @@
}
///
- /// Looks up a localized string similar to Geeft deze informatie weer..
- ///
- internal static string CommandHelp_Detailed {
- get {
- return ResourceManager.GetString("CommandHelp_Detailed", resourceCulture);
- }
- }
-
- ///
/// Looks up a localized string similar to {0} is geen geldige opdracht..
///
internal static string CommandInvalid_Command_0_Is_not_valid {
@@ -136,15 +127,6 @@
}
///
- /// Looks up a localized string similar to MIGRATIEHULPPROGRAMMA {0}.
- ///
- internal static string CommandSupported_Command_0_Brief {
- get {
- return ResourceManager.GetString("CommandSupported_Command_0_Brief", resourceCulture);
- }
- }
-
- ///
/// Looks up a localized string similar to Controleert of het projectbestand dat te vinden is in het bronprojectpad gemigreerd kan worden..
///
internal static string CommandSupported_Detailed {
@@ -174,10 +156,19 @@
///
/// Looks up a localized string similar to Dit hulpprogramma kan worden gebruikt om een projectbestand in het formaat van een eerdere versie van Ringtoets te migreren naar het formaat van de huidige versie van Ringtoets..
///
- internal static string RingtoetsMigrationTool_Info {
+ internal static string RingtoetsMigrationTool_ApplicationDescription {
get {
- return ResourceManager.GetString("RingtoetsMigrationTool_Info", resourceCulture);
+ return ResourceManager.GetString("RingtoetsMigrationTool_ApplicationDescription", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to MIGRATIEHULPPROGRAMMA.
+ ///
+ internal static string RingtoetsMigrationTool_ApplicationName {
+ get {
+ return ResourceManager.GetString("RingtoetsMigrationTool_ApplicationName", resourceCulture);
+ }
+ }
}
}
Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.resx
===================================================================
diff -u -r0930763dbd895350070e8075dc9d7ba1bd89cf0f -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.resx (.../Resources.resx) (revision 0930763dbd895350070e8075dc9d7ba1bd89cf0f)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/Properties/Resources.resx (.../Resources.resx) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -117,12 +117,6 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- Geeft deze informatie weer.
-
-
- {0} is geen geldige opdracht.
-
MIGRATIEHULPPROGRAMMA bronprojectpad doelprojectpad
@@ -138,10 +132,7 @@
Controleert of het projectbestand dat te vinden is in het bronprojectpad gemigreerd kan worden.
-
- MIGRATIEHULPPROGRAMMA {0}
-
-
+
Dit hulpprogramma kan worden gebruikt om een projectbestand in het formaat van een eerdere versie van Ringtoets te migreren naar het formaat van de huidige versie van Ringtoets.
@@ -150,4 +141,10 @@
Het projectbestand is niet ondersteund.
+
+ {0} is geen geldige opdracht.
+
+
+ MIGRATIEHULPPROGRAMMA
+
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationConsole.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationConsole.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationConsole.cs (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -0,0 +1,107 @@
+// 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;
+using Application.Ringtoets.Migration;
+using Application.Ringtoets.MigrationConsole.Properties;
+using Migration.Console;
+using Ringtoets.Common.Utils;
+
+namespace Application.Ringtoets.MigrationConsole
+{
+ ///
+ /// Console application that can migrate a Ringtoets database file to a newer version.
+ ///
+ public class RingtoetsMigrationConsole : ConsoleBase
+ {
+ public RingtoetsMigrationConsole() : base(Resources.RingtoetsMigrationTool_ApplicationName,
+ Resources.RingtoetsMigrationTool_ApplicationDescription) {}
+
+ protected override void ExecuteCommand(string[] args)
+ {
+ switch (args.Length)
+ {
+ case 1:
+ IsVersionSupportedCommand(args[0]);
+ break;
+ case 2:
+ MigrateCommand(args[0], args[1]);
+ break;
+ default:
+ string command = string.Join(" ", args);
+ InvalidCommand(command);
+ break;
+ }
+ }
+
+ protected override void DisplayAllCommands()
+ {
+ base.DisplayAllCommands();
+ ShowMigrateCommand();
+ ShowSupportedCommand();
+ }
+
+ #region Commands
+
+ private static void InvalidCommand(string command)
+ {
+ throw new NotSupportedException(string.Format(Resources.CommandInvalid_Command_0_Is_not_valid, command));
+ }
+
+ private static void IsVersionSupportedCommand(string location)
+ {
+ var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
+ var versionedFile = new RingtoetsVersionedFile(location);
+ var version = versionedFile.GetVersion();
+
+ bool isSupported = migrator.IsVersionSupported(version);
+ Console.WriteLine(isSupported
+ ? Resources.CommandSupported_File_Supported
+ : Resources.CommandSupported_File_Not_Supported);
+ }
+
+ private static void ShowSupportedCommand()
+ {
+ Console.WriteLine(Resources.CommandSupported_Brief);
+ ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandSupported_Detailed);
+ }
+
+ private static void MigrateCommand(string filepath, string toFilepath)
+ {
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
+ var sourceFile = new RingtoetsVersionedFile(filepath);
+
+ migrator.Migrate(sourceFile, toVersion, toFilepath);
+ Console.WriteLine(Resources.CommandMigrate_Successful_Migration_From_Location_0_To_Location_1,
+ filepath, toFilepath);
+ }
+
+ private static void ShowMigrateCommand()
+ {
+ Console.WriteLine(Resources.CommandMigrate_Brief);
+ ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandMigrate_Detailed);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs
===================================================================
diff -u -ra9a950a638de8b5385c00db876328cdac5b4728f -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs (.../RingtoetsMigrationTool.cs) (revision a9a950a638de8b5385c00db876328cdac5b4728f)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs (.../RingtoetsMigrationTool.cs) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -19,27 +19,13 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
-using System;
-using System.Linq;
-using Application.Ringtoets.Migration;
-using Application.Ringtoets.MigrationConsole.Properties;
-using Migration.Console;
-using Migration.Scripts.Data.Exceptions;
-using Ringtoets.Common.Utils;
-using MigrationConsoleResources = Migration.Console.Properties.Resources;
-
namespace Application.Ringtoets.MigrationConsole
{
///
- /// Console application that can migrate a Ringtoets database file to a newer version.
+ /// Entry point to the console application that can migrate a Ringtoets database file to a newer version.
///
public static class RingtoetsMigrationTool
{
- private const string commandMigrate = "--migrate";
- private const string commandVersionSupported = "--supported";
- private const string commandHelp = "--help";
- private const string commandHelpShort = "-h";
-
///
/// Main Ringtoets migration application.
///
@@ -51,130 +37,8 @@
///
public static void Main(string[] args)
{
- try
- {
- ExecuteCommand(args);
- }
- catch (Exception exception)
- {
- DisplayException(exception);
- DisplayAllCommands();
-
- if (exception is CriticalMigrationException || exception is NotSupportedException)
- {
- Exit(ErrorCode.ErrorBadCommand);
- return;
- }
- Exit(ErrorCode.ErrorInvalidCommandLine);
- return;
- }
-
- Exit(ErrorCode.ErrorSuccess);
+ var ringtoetsMigrationTool = new RingtoetsMigrationConsole();
+ ringtoetsMigrationTool.ExecuteConsoleTool(args);
}
-
- private static void Exit(ErrorCode errorCode)
- {
- EnvironmentControl.Instance.Exit(errorCode);
- }
-
- private static void DisplayException(Exception exception)
- {
- ConsoleHelper.WriteErrorLine(exception.Message);
- if (exception.InnerException != null)
- {
- ConsoleHelper.WriteErrorLine(MigrationConsoleResources.Message_Inner_Exception_0,
- exception.InnerException.Message);
- }
- ConsoleHelper.WriteErrorLine("");
- }
-
- private static void ExecuteCommand(string[] args)
- {
- string command = args.FirstOrDefault() ?? commandHelp;
- if (command.Equals(commandHelp) || command.Equals(commandHelpShort))
- {
- DisplayAllCommands();
- return;
- }
-
- var length = args.Length;
- switch (length)
- {
- case 1:
- IsVersionSupportedCommand(args[0]);
- break;
- case 2:
- MigrateCommand(args[0], args[1]);
- break;
- default:
- command = string.Join(" ", args);
- InvalidCommand(command);
- break;
- }
- }
-
- private static void DisplayAllCommands()
- {
- Console.WriteLine(Resources.RingtoetsMigrationTool_Info);
- Console.WriteLine();
- Console.WriteLine(Resources.CommandSupported_Command_0_Brief, commandHelpShort);
- Console.WriteLine(Resources.CommandSupported_Command_0_Brief, commandHelp);
- ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandHelp_Detailed);
- ShowMigrateCommand();
- ShowSupportedCommand();
- }
-
- #region Invalid Command
-
- private static void InvalidCommand(string command)
- {
- throw new NotSupportedException(string.Format(Resources.CommandInvalid_Command_0_Is_not_valid, command));
- }
-
- #endregion
-
- #region Version Supported Command
-
- private static void IsVersionSupportedCommand(string location)
- {
- var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
- var versionedFile = new RingtoetsVersionedFile(location);
- var version = versionedFile.GetVersion();
-
- bool isSupported = migrator.IsVersionSupported(version);
- Console.WriteLine(isSupported
- ? Resources.CommandSupported_File_Supported
- : Resources.CommandSupported_File_Not_Supported);
- }
-
- private static void ShowSupportedCommand()
- {
- Console.WriteLine(Resources.CommandSupported_Brief);
- ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandSupported_Detailed);
- }
-
- #endregion
-
- #region Migrate Command
-
- private static void MigrateCommand(string filepath, string toFilepath)
- {
- string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
-
- var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
- var sourceFile = new RingtoetsVersionedFile(filepath);
-
- migrator.Migrate(sourceFile, toVersion, toFilepath);
- Console.WriteLine(Resources.CommandMigrate_Successful_Migration_From_Location_0_To_Location_1,
- filepath, toFilepath);
- }
-
- private static void ShowMigrateCommand()
- {
- Console.WriteLine(Resources.CommandMigrate_Brief);
- ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandMigrate_Detailed);
- }
-
- #endregion
}
}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/Application.Ringtoets.MigrationConsole.Test.csproj
===================================================================
diff -u -r0930763dbd895350070e8075dc9d7ba1bd89cf0f -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/Application.Ringtoets.MigrationConsole.Test.csproj (.../Application.Ringtoets.MigrationConsole.Test.csproj) (revision 0930763dbd895350070e8075dc9d7ba1bd89cf0f)
+++ Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/Application.Ringtoets.MigrationConsole.Test.csproj (.../Application.Ringtoets.MigrationConsole.Test.csproj) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -47,6 +47,7 @@
Properties\GlobalAssembly.cs
+
Index: Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/RingtoetsMigrationConsoleTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/RingtoetsMigrationConsoleTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.MigrationConsole.Test/RingtoetsMigrationConsoleTest.cs (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -0,0 +1,222 @@
+// 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;
+using System.IO;
+using Application.Ringtoets.Migration;
+using Core.Common.TestUtil;
+using Migration.Console;
+using Migration.Console.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Utils;
+
+namespace Application.Ringtoets.MigrationConsole.Test
+{
+ [TestFixture]
+ public class RingtoetsMigrationConsoleTest
+ {
+ private TestEnvironmentControl environmentControl;
+
+ [SetUp]
+ public void SetUp()
+ {
+ environmentControl = new TestEnvironmentControl();
+ EnvironmentControl.Instance = environmentControl;
+ }
+
+ [Test]
+ public void Constructor_ExpectedProperties()
+ {
+ // Call
+ var console = new RingtoetsMigrationConsole();
+
+ // Assert
+ Assert.IsInstanceOf(console);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_NoArguments_WritesHelpToConsole()
+ {
+ // Setup
+ var console = new RingtoetsMigrationConsole();
+ string consoleText;
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ console.ExecuteConsoleTool(new string[] { });
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ var expectedText = GetConsoleFullDescription();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_InvalidArguments_WritesHelpToConsoleWithErrorCode()
+ {
+ // Setup
+ var console = new RingtoetsMigrationConsole();
+ string[] invalidCommand =
+ {
+ "0",
+ "1",
+ "2"
+ };
+ string consoleText;
+
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ console.ExecuteConsoleTool(invalidCommand);
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ var expectedText = $"{string.Join(" ", invalidCommand)} is geen geldige opdracht."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ [TestCase("FullTestProject164.rtd", true)]
+ [TestCase("UnsupportedVersion8.rtd", false)]
+ public void GivenConsole_WhenVersionSupportedCall_ThenReturnedIfSupported(string file, bool isSupported)
+ {
+ // Given
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, file);
+ var console = new RingtoetsMigrationConsole();
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath
+ });
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Then
+ Assert.AreEqual($@"Het projectbestand is {(isSupported ? "" : "niet ")}ondersteund."
+ + Environment.NewLine, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion()
+ {
+ // Given
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
+ string targetFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, Path.GetRandomFileName());
+ var console = new RingtoetsMigrationConsole();
+
+ using (new FileDisposeHelper(targetFilePath))
+ {
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Then
+ var expected = $"Het bestand '{sourceFilePath}' is succesvol gemigreerd naar '{targetFilePath}'."
+ + Environment.NewLine;
+ Assert.AreEqual(expected, consoleText);
+ var toVersionedFile = new RingtoetsVersionedFile(targetFilePath);
+ string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion());
+ }
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode()
+ {
+ // Given
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
+ string targetFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, Path.GetRandomFileName());
+
+ var console = new RingtoetsMigrationConsole();
+
+ string consoleText;
+ using (new FileDisposeHelper(targetFilePath))
+ using (File.Create(targetFilePath))
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Then
+ StringAssert.StartsWith("Er is een onverwachte fout opgetreden tijdens het verplaatsen van het gemigreerde bestand '",
+ consoleText);
+ StringAssert.EndsWith($"' naar '{targetFilePath}'." + Environment.NewLine
+ + "Het besturingssysteem geeft de volgende melding: "
+ + $"The process cannot access the file '{targetFilePath}' because it is being used by another process."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription(), consoleText);
+ Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
+ }
+
+ private static string GetConsoleFullDescription()
+ {
+ return "Dit hulpprogramma kan worden gebruikt om een projectbestand in het formaat van een "
+ + "eerdere versie van Ringtoets te migreren naar het formaat van de huidige versie van Ringtoets."
+ + Environment.NewLine + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA -h" + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA --help" + Environment.NewLine
+ + " Geeft deze informatie weer." + Environment.NewLine + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA bronprojectpad doelprojectpad" + Environment.NewLine
+ + " Voert de migratie uit van het projectbestand dat te vinden is in het "
+ + Environment.NewLine
+ + " bronprojectpad en slaat het resulterende projectbestand op in het doe"
+ + Environment.NewLine
+ + " lprojectpad."
+ + Environment.NewLine + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA bronprojectpad" + Environment.NewLine
+ + " Controleert of het projectbestand dat te vinden is in het bronproject"
+ + Environment.NewLine
+ + " pad gemigreerd kan worden." + Environment.NewLine + Environment.NewLine;
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj
===================================================================
diff -u -rbece78e24185a5156bc10f7ec7875e4510b6934c -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision bece78e24185a5156bc10f7ec7875e4510b6934c)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -86,6 +86,10 @@
{f5b43c29-6169-4e9a-859e-09090330b94e}
Ringtoets.ClosingStructures.Data.TestUtil
+
+ {6A074D65-A81C-4C1C-8E24-F36C916E4ED7}
+ Ringtoets.Common.Utils
+
{D1068432-C172-4AA6-847B-D9DEB4C6DE26}
Ringtoets.DuneErosion.Data
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs
===================================================================
diff -u -r946b237385a53349d539eb6432b808b7fd7295b2 -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision 946b237385a53349d539eb6432b808b7fd7295b2)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -24,6 +24,7 @@
using Application.Ringtoets.Storage.Properties;
using Core.Common.IO;
using NUnit.Framework;
+using Ringtoets.Common.Utils;
using Ringtoets.Integration.Data;
namespace Application.Ringtoets.Storage.TestUtil
@@ -42,7 +43,7 @@
public static void CreateCorruptDatabaseFile(string databaseFilePath)
{
CreateDatabaseFile(databaseFilePath, GetCorruptSchema());
- AddVersionEntity(databaseFilePath, "5");
+ AddVersionEntity(databaseFilePath, RingtoetsVersionHelper.GetCurrentDatabaseVersion());
}
///
@@ -54,7 +55,7 @@
public static void CreateCompleteDatabaseFileWithoutProjectData(string databaseFilePath)
{
CreateCompleteDatabaseFileEmpty(databaseFilePath);
- AddVersionEntity(databaseFilePath, "5");
+ AddVersionEntity(databaseFilePath, RingtoetsVersionHelper.GetCurrentDatabaseVersion());
}
///
Index: Migration/Console/src/Migration.Console/ConsoleBase.cs
===================================================================
diff -u
--- Migration/Console/src/Migration.Console/ConsoleBase.cs (revision 0)
+++ Migration/Console/src/Migration.Console/ConsoleBase.cs (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -0,0 +1,133 @@
+// 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 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;
+using System.Linq;
+using Migration.Console.Properties;
+using Migration.Scripts.Data.Exceptions;
+using SystemConsole = System.Console;
+
+namespace Migration.Console
+{
+ ///
+ /// Base console application.
+ ///
+ public abstract class ConsoleBase
+ {
+ private const string commandHelp = "--help";
+ private const string commandHelpShort = "-h";
+ private readonly string applicationName;
+ private readonly string applicationDescription;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The name of the application as it can be called in the command line.
+ /// The description of the application.
+ /// Thrown when any of the input parameters is null.
+ protected ConsoleBase(string applicationName, string applicationDescription)
+ {
+ if (applicationName == null)
+ {
+ throw new ArgumentNullException(nameof(applicationName));
+ }
+ if (applicationDescription == null)
+ {
+ throw new ArgumentNullException(nameof(applicationDescription));
+ }
+ this.applicationName = applicationName;
+ this.applicationDescription = applicationDescription;
+ }
+
+ ///
+ /// Executes a command based upon the arguments provided.
+ ///
+ /// The arguments that determine which command to execute.
+ /// By default, the help command is executed.
+ public void ExecuteConsoleTool(string[] args)
+ {
+ try
+ {
+ ParseCommand(args);
+ }
+ catch (Exception exception)
+ {
+ DisplayException(exception);
+ DisplayAllCommands();
+
+ if (exception is CriticalMigrationException || exception is NotSupportedException)
+ {
+ Exit(ErrorCode.ErrorBadCommand);
+ return;
+ }
+ Exit(ErrorCode.ErrorInvalidCommandLine);
+ return;
+ }
+
+ Exit(ErrorCode.ErrorSuccess);
+ }
+
+ ///
+ /// Writes all commands to the .
+ ///
+ protected virtual void DisplayAllCommands()
+ {
+ SystemConsole.WriteLine(applicationDescription);
+ SystemConsole.WriteLine();
+ SystemConsole.WriteLine(string.Concat(applicationName, " ", commandHelpShort));
+ SystemConsole.WriteLine(string.Concat(applicationName, " ", commandHelp));
+ ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandHelp_Detailed);
+ }
+
+ ///
+ /// Executes a command based upon the arguments provided.
+ ///
+ /// The arguments that determine which command to execute.
+ /// Thrown when the command failed.
+ protected abstract void ExecuteCommand(string[] args);
+
+ private void ParseCommand(string[] args)
+ {
+ string command = args?.FirstOrDefault() ?? commandHelp;
+ if (command.Equals(commandHelp) || command.Equals(commandHelpShort))
+ {
+ DisplayAllCommands();
+ return;
+ }
+ ExecuteCommand(args);
+ }
+
+ private static void Exit(ErrorCode errorCode)
+ {
+ EnvironmentControl.Instance.Exit(errorCode);
+ }
+
+ private static void DisplayException(Exception exception)
+ {
+ ConsoleHelper.WriteErrorLine(exception.Message);
+ if (exception.InnerException != null)
+ {
+ ConsoleHelper.WriteErrorLine(Resources.Message_Inner_Exception_0, exception.InnerException.Message);
+ }
+ ConsoleHelper.WriteErrorLine("");
+ }
+ }
+}
\ No newline at end of file
Index: Migration/Console/src/Migration.Console/Migration.Console.csproj
===================================================================
diff -u -radb7a69497e2221e75420ccf5f5d7407321870dd -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Migration/Console/src/Migration.Console/Migration.Console.csproj (.../Migration.Console.csproj) (revision adb7a69497e2221e75420ccf5f5d7407321870dd)
+++ Migration/Console/src/Migration.Console/Migration.Console.csproj (.../Migration.Console.csproj) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -42,6 +42,7 @@
+
True
Index: Migration/Console/src/Migration.Console/Properties/Resources.Designer.cs
===================================================================
diff -u -r56e690b056dd0901609e651f6ac3c010d3d002b7 -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Migration/Console/src/Migration.Console/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56e690b056dd0901609e651f6ac3c010d3d002b7)
+++ Migration/Console/src/Migration.Console/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -82,11 +82,11 @@
}
///
- /// Looks up a localized string similar to Er is een verkeerd aantal parameters opgegeven voor de opdracht '{0}'.
+ /// Looks up a localized string similar to Geeft deze informatie weer..
///
- public static string Command_0_Incorrect_number_of_parameters {
+ public static string CommandHelp_Detailed {
get {
- return ResourceManager.GetString("Command_0_Incorrect_number_of_parameters", resourceCulture);
+ return ResourceManager.GetString("CommandHelp_Detailed", resourceCulture);
}
}
Index: Migration/Console/src/Migration.Console/Properties/Resources.resx
===================================================================
diff -u -r5af53bf87a1ba736d10a3ec77637d26716d507f3 -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Migration/Console/src/Migration.Console/Properties/Resources.resx (.../Resources.resx) (revision 5af53bf87a1ba736d10a3ec77637d26716d507f3)
+++ Migration/Console/src/Migration.Console/Properties/Resources.resx (.../Resources.resx) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -117,8 +117,8 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- Er is een verkeerd aantal parameters opgegeven voor de opdracht '{0}'
+
+ Geeft deze informatie weer.
Het besturingssysteem geeft de volgende melding: {0}
Index: Migration/Console/test/Migration.Console.Test/ConsoleBaseTest.cs
===================================================================
diff -u
--- Migration/Console/test/Migration.Console.Test/ConsoleBaseTest.cs (revision 0)
+++ Migration/Console/test/Migration.Console.Test/ConsoleBaseTest.cs (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -0,0 +1,257 @@
+// 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 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;
+using Migration.Console.TestUtil;
+using Migration.Scripts.Data.Exceptions;
+using NUnit.Framework;
+
+namespace Migration.Console.Test
+{
+ [TestFixture]
+ public class ConsoleBaseTest
+ {
+ private const string applicationName = "name";
+ private const string applicationDescription = "applicationDescription";
+ private TestEnvironmentControl environmentControl;
+
+ [SetUp]
+ public void SetUp()
+ {
+ environmentControl = new TestEnvironmentControl();
+ EnvironmentControl.Instance = environmentControl;
+ }
+
+ [Test]
+ public void Constructor_ApplicationNameNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new SimpleConsoleBase(null, applicationDescription);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("applicationName", paramName);
+ }
+
+ [Test]
+ public void Constructor_ApplicationDescriptionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new SimpleConsoleBase(applicationName, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("applicationDescription", paramName);
+ }
+
+ [Test]
+ public void DisplayAllCommands_WritesAllCommandsToConsole()
+ {
+ // Setup
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ consoleBase.WriteDisplayAllCommands();
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ Assert.AreEqual(GetConsoleFullDescription(), consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_ArgsNull_WritesAllCommandsToConsole()
+ {
+ // Setup
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ consoleBase.SimpleExecuteConsoleTool(null);
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ Assert.AreEqual(GetConsoleFullDescription(), consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ [TestCase("-h")]
+ [TestCase("--help")]
+ public void ExecuteConsoleTool_ArgsIsHelp_WritesAllCommandsToConsole(string command)
+ {
+ // Setup
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ consoleBase.SimpleExecuteConsoleTool(new[]
+ {
+ command
+ });
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ Assert.AreEqual(GetConsoleFullDescription(), consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_ArgsIsInvalid_CallsExecuteCommand()
+ {
+ // Setup
+ const string command = "invalid command";
+ var commandArgs = new[]
+ {
+ command
+ };
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+
+ consoleBase.SimpleExecuteConsoleTool(commandArgs);
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ Assert.AreEqual("", consoleText);
+ Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_BadCommand_WritesErrorWithErrorCode()
+ {
+ // Setup
+ const string command = "invalid command";
+ var commandArgs = new[]
+ {
+ command
+ };
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ consoleBase.ExceptionToBeThrown = new CriticalMigrationException("I was told to be thrown.");
+
+ // Call
+ consoleBase.SimpleExecuteConsoleTool(commandArgs);
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ string expectedtext = "I was told to be thrown." + Environment.NewLine
+ + Environment.NewLine + GetConsoleFullDescription();
+ Assert.AreEqual(expectedtext, consoleText);
+ Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
+ Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_ThrowsException_WritesErrorWithErrorCode()
+ {
+ // Setup
+ const string command = "invalid command";
+ var commandArgs = new[]
+ {
+ command
+ };
+ var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);
+
+ string consoleText;
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ consoleBase.ExceptionToBeThrown = new Exception("I was told to be thrown.", new Exception("inner exception."));
+
+ // Call
+ consoleBase.SimpleExecuteConsoleTool(commandArgs);
+
+ consoleText = consoleOutput.GetConsoleOutput();
+ }
+
+ // Assert
+ string expectedtext = "I was told to be thrown." + Environment.NewLine
+ + "Het besturingssysteem geeft de volgende melding: inner exception."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription();
+ Assert.AreEqual(expectedtext, consoleText);
+ Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
+ Assert.AreEqual(ErrorCode.ErrorInvalidCommandLine, environmentControl.ErrorCodeCalled);
+ }
+
+ private static string GetConsoleFullDescription()
+ {
+ return applicationDescription
+ + Environment.NewLine + Environment.NewLine
+ + $"{applicationName} -h" + Environment.NewLine
+ + $"{applicationName} --help" + Environment.NewLine
+ + " Geeft deze informatie weer." + Environment.NewLine + Environment.NewLine;
+ }
+
+ private class SimpleConsoleBase : ConsoleBase
+ {
+ public SimpleConsoleBase(string applicationName, string applicationDescription)
+ : base(applicationName, applicationDescription) {}
+
+ public Exception ExceptionToBeThrown { private get; set; }
+
+ public string[] ExecuteCommandArguments { get; private set; }
+
+ public void SimpleExecuteConsoleTool(string[] args)
+ {
+ ExecuteConsoleTool(args);
+ }
+
+ public void WriteDisplayAllCommands()
+ {
+ DisplayAllCommands();
+ }
+
+ protected override void ExecuteCommand(string[] args)
+ {
+ ExecuteCommandArguments = args;
+ if (ExceptionToBeThrown != null)
+ {
+ throw ExceptionToBeThrown;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Migration/Console/test/Migration.Console.Test/Migration.Console.Test.csproj
===================================================================
diff -u -radb7a69497e2221e75420ccf5f5d7407321870dd -r896b05735de6229ba6108507c79d8207fa3f2d26
--- Migration/Console/test/Migration.Console.Test/Migration.Console.Test.csproj (.../Migration.Console.Test.csproj) (revision adb7a69497e2221e75420ccf5f5d7407321870dd)
+++ Migration/Console/test/Migration.Console.Test/Migration.Console.Test.csproj (.../Migration.Console.Test.csproj) (revision 896b05735de6229ba6108507c79d8207fa3f2d26)
@@ -46,6 +46,7 @@
Properties\GlobalAssembly.cs
+
@@ -57,6 +58,10 @@
+
+ {D08DB9E2-6861-44C8-A725-71A70274CC77}
+ Migration.Scripts.Data
+
{2E2C9B96-E72A-4C10-AA54-A5381FE30B0D}
Migration.Console