Index: Application/Ringtoets/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj
===================================================================
diff -u -r85f5cbee4721291b681d94767dd41845a28ad4ad -r7ad4fee36379181bfd053b3ea30dca613d776d71
--- Application/Ringtoets/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj (.../Application.Riskeer.Migration.Console.csproj) (revision 85f5cbee4721291b681d94767dd41845a28ad4ad)
+++ Application/Ringtoets/src/Application.Riskeer.Migration.Console/Application.Riskeer.Migration.Console.csproj (.../Application.Riskeer.Migration.Console.csproj) (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -18,8 +18,8 @@
True
Resources.resx
-
-
+
+
Fisheye: Tag 7ad4fee36379181bfd053b3ea30dca613d776d71 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Riskeer.Migration.Console/RingtoetsMigrationConsole.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 7ad4fee36379181bfd053b3ea30dca613d776d71 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Riskeer.Migration.Console/RingtoetsMigrationTool.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationConsole.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationConsole.cs (revision 0)
+++ Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationConsole.cs (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -0,0 +1,143 @@
+// Copyright (C) Stichting Deltares 2018. 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.Riskeer.Migration.Console.Properties;
+using Core.Common.Util;
+using Migration.Console;
+using Ringtoets.Common.Util;
+using Riskeer.Migration.Core;
+using MigrationCoreStorageResources = Migration.Core.Storage.Properties.Resources;
+using RiskeerMigrationCoreResources = Riskeer.Migration.Core.Properties.Resources;
+
+namespace Application.Riskeer.Migration.Console
+{
+ ///
+ /// Console application that can migrate a Ringtoets database file to a newer version.
+ ///
+ public class RiskeerMigrationConsole : ConsoleBase
+ {
+ private static readonly string currentDatabaseVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ ///
+ /// Creates a new instance of .
+ ///
+ public RiskeerMigrationConsole() : base(Resources.RingtoetsMigrationTool_ApplicationName,
+ GetApplicationDescription()) {}
+
+ 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 DisplayCommands()
+ {
+ ShowSupportedCommand();
+ ShowMigrateCommand();
+ }
+
+ private static string GetApplicationDescription()
+ {
+ return string.Format(Resources.RingtoetsMigrationTool_ApplicationDescription_Version_0, currentDatabaseVersion);
+ }
+
+ #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)
+ {
+ ValidateIsVersionSupportedArgument(location);
+
+ var versionedFile = new RingtoetsVersionedFile(location);
+ var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
+ string version = versionedFile.GetVersion();
+
+ bool isSupported = migrator.IsVersionSupported(version);
+
+ if (isSupported)
+ {
+ System.Console.WriteLine(Resources.CommandSupported_File_Able_To_Migrate_To_Version_0, currentDatabaseVersion);
+ }
+ else
+ {
+ ConsoleHelper.WriteErrorLine(MigrationCoreStorageResources.Migrate_From_Version_0_To_Version_1_Not_Supported,
+ version, currentDatabaseVersion);
+ }
+ }
+
+ private static void ValidateIsVersionSupportedArgument(string location)
+ {
+ if (!IOUtils.IsValidFilePath(location))
+ {
+ throw new ArgumentException(RiskeerMigrationCoreResources.CommandSupported_Source_Not_Valid_Path);
+ }
+ }
+
+ private static void ShowSupportedCommand()
+ {
+ System.Console.WriteLine(Resources.CommandSupported_Brief);
+ ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandSupported_Detailed);
+ }
+
+ private static void MigrateCommand(string filePath, string toFilePath)
+ {
+ ValidateMigrationArguments(filePath, toFilePath);
+ var migrator = new RingtoetsSqLiteDatabaseFileMigrator();
+ var sourceFile = new RingtoetsVersionedFile(filePath);
+
+ migrator.Migrate(sourceFile, currentDatabaseVersion, toFilePath);
+ System.Console.WriteLine(Resources.CommandMigrate_Successful_Migration_From_Location_0_To_Location_1_Version_2,
+ filePath, toFilePath, currentDatabaseVersion);
+ }
+
+ private static void ValidateMigrationArguments(string filePath, string toFilePath)
+ {
+ if (!(IOUtils.IsValidFilePath(filePath) && IOUtils.IsValidFilePath(toFilePath)))
+ {
+ throw new ArgumentException(Resources.CommandMigrate_Source_Or_Destination_Not_Valid_Path);
+ }
+ }
+
+ private static void ShowMigrateCommand()
+ {
+ System.Console.WriteLine(Resources.CommandMigrate_Brief);
+ ConsoleHelper.WriteCommandDescriptionLine(Resources.CommandMigrate_Detailed);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs (revision 0)
+++ Application/Ringtoets/src/Application.Riskeer.Migration.Console/RiskeerMigrationTool.cs (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -0,0 +1,44 @@
+// Copyright (C) Stichting Deltares 2018. 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.
+
+namespace Application.Riskeer.Migration.Console
+{
+ ///
+ /// Entry point to the console application that can migrate a Ringtoets database file to a newer version.
+ ///
+ public static class RiskeerMigrationTool
+ {
+ ///
+ /// Main Ringtoets migration application.
+ ///
+ /// Arguments
+ /// Accepted commands:
+ /// - --help Shows help menu,
+ /// - --supported Returns if the database file is supported,
+ /// - --migrate Migrates the database file to a newer version.
+ ///
+ public static void Main(string[] args)
+ {
+ var ringtoetsMigrationTool = new RiskeerMigrationConsole();
+ ringtoetsMigrationTool.ExecuteConsoleTool(args);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/Application.Riskeer.Migration.Console.Test.csproj
===================================================================
diff -u -rd9d8ca6b9f19135fe85270c2e52cfdff63656724 -r7ad4fee36379181bfd053b3ea30dca613d776d71
--- Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/Application.Riskeer.Migration.Console.Test.csproj (.../Application.Riskeer.Migration.Console.Test.csproj) (revision d9d8ca6b9f19135fe85270c2e52cfdff63656724)
+++ Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/Application.Riskeer.Migration.Console.Test.csproj (.../Application.Riskeer.Migration.Console.Test.csproj) (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -20,8 +20,8 @@
-
-
+
+
Fisheye: Tag 7ad4fee36379181bfd053b3ea30dca613d776d71 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RingtoetsMigrationConsoleTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 7ad4fee36379181bfd053b3ea30dca613d776d71 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RingtoetsMigrationToolTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationConsoleTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationConsoleTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationConsoleTest.cs (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -0,0 +1,274 @@
+// Copyright (C) Stichting Deltares 2018. 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.Collections.Generic;
+using Core.Common.TestUtil;
+using Migration.Console;
+using Migration.Console.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Util;
+using Riskeer.Migration.Core;
+using Riskeer.Migration.Core.TestUtil;
+
+namespace Application.Riskeer.Migration.Console.Test
+{
+ [TestFixture]
+ [Explicit("Migration Console tests are disabled.")]
+ public class RiskeerMigrationConsoleTest
+ {
+ private TestEnvironmentControl environmentControl;
+
+ [SetUp]
+ public void SetUp()
+ {
+ environmentControl = new TestEnvironmentControl();
+ EnvironmentControl.Instance = environmentControl;
+ }
+
+ [Test]
+ public void Constructor_ExpectedProperties()
+ {
+ // Call
+ var console = new RiskeerMigrationConsole();
+
+ // Assert
+ Assert.IsInstanceOf(console);
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_NoArguments_WritesHelpToConsole()
+ {
+ // Setup
+ var console = new RiskeerMigrationConsole();
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ console.ExecuteConsoleTool(new string[]
+ {});
+
+ // Assert
+ string expectedText = Environment.NewLine + GetConsoleFullDescription();
+ string consoleText = consoleOutput.GetConsoleOutput();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_InvalidArguments_WritesHelpToConsoleWithErrorCode()
+ {
+ // Setup
+ var console = new RiskeerMigrationConsole();
+ string[] invalidCommand =
+ {
+ "0",
+ "1",
+ "2"
+ };
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ console.ExecuteConsoleTool(invalidCommand);
+
+ // Assert
+ string expectedText = Environment.NewLine
+ + $"{string.Join(" ", invalidCommand)} is geen geldige opdracht."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription();
+ string consoleText = consoleOutput.GetConsoleOutput();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ public void ExecuteConsoleTool_InvalidArgumentsForMigrate_WritesHelpToConsoleWithErrorCode()
+ {
+ // Setup
+ var console = new RiskeerMigrationConsole();
+ string[] invalidCommand =
+ {
+ "",
+ ""
+ };
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ console.ExecuteConsoleTool(invalidCommand);
+
+ // Assert
+ string expectedText = Environment.NewLine
+ + "Bron- en doelprojectpad moeten geldige bestandspaden zijn."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription();
+ string consoleText = consoleOutput.GetConsoleOutput();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorInvalidCommandLine, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ [TestCaseSource(nameof(RingtoetsFilesToMigrate))]
+ public void GivenConsole_WhenVersionSupportedCall_ThenReturnedIfSupported(string file, string fileVersion, bool isSupported)
+ {
+ // Given
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, file);
+ var console = new RiskeerMigrationConsole();
+ string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath
+ });
+
+ // Then
+ string consoleText = consoleOutput.GetConsoleOutput();
+ string expectedText = isSupported
+ ? Environment.NewLine
+ + $@"Het projectbestand kan gemigreerd worden naar versie '{expectedVersion}'."
+ + Environment.NewLine
+ : Environment.NewLine
+ + $"Het migreren van een projectbestand met versie '{fileVersion}' naar versie '{expectedVersion}' is niet ondersteund."
+ + Environment.NewLine;
+
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion()
+ {
+ // Given
+ string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationConsoleTest)}.{nameof(GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion)}");
+ var console = new RiskeerMigrationConsole();
+ string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ using (new FileDisposeHelper(targetFilePath))
+ {
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ // Then
+ string expected = Environment.NewLine
+ + $"Het projectbestand '{sourceFilePath}' is succesvol gemigreerd naar '{targetFilePath}' (versie {expectedVersion})."
+ + Environment.NewLine;
+ string consoleText = consoleOutput.GetConsoleOutput();
+ Assert.AreEqual(expected, consoleText);
+
+ var toVersionedFile = new RingtoetsVersionedFile(targetFilePath);
+ Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion());
+ }
+ }
+
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode()
+ {
+ // Given
+ string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationConsoleTest)}.{nameof(GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode)}");
+
+ var console = new RiskeerMigrationConsole();
+
+ using (var fileDisposeHelper = new FileDisposeHelper(targetFilePath))
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ fileDisposeHelper.LockFiles();
+
+ // When
+ console.ExecuteConsoleTool(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ // Then
+ string consoleText = consoleOutput.GetConsoleOutput();
+ StringAssert.StartsWith(Environment.NewLine + "Het gemigreerde projectbestand is aangemaakt op '",
+ consoleText);
+ StringAssert.EndsWith($"', maar er is een onverwachte fout opgetreden tijdens het verplaatsen naar '{targetFilePath}'."
+ + Environment.NewLine
+ + "Het besturingssysteem geeft de volgende melding: "
+ + Environment.NewLine
+ + $"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()
+ {
+ string currentDatabaseVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ 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 ({currentDatabaseVersion})."
+ + Environment.NewLine + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA -h" + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA --help" + Environment.NewLine
+ + " Geeft deze informatie weer." + 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
+ + "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;
+ }
+
+ #region Test cases
+
+ private static IEnumerable RingtoetsFilesToMigrate()
+ {
+ string unsupportedProjectFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
+ var unsupportedVersionedFile = new RingtoetsVersionedFile(unsupportedProjectFilePath);
+ string unsupportedVersion = unsupportedVersionedFile.GetVersion();
+
+ string supportedProjectFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ var supportedVersionedFile = new RingtoetsVersionedFile(supportedProjectFilePath);
+ string supportedVersion = supportedVersionedFile.GetVersion();
+
+ yield return new TestCaseData(unsupportedProjectFilePath, unsupportedVersion, false).SetName("UnsupportedRingtoetsVersion");
+ yield return new TestCaseData(supportedProjectFilePath, supportedVersion, true).SetName("SupportedRingtoetsVersion");
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationToolTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationToolTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Riskeer.Migration.Console.Test/RiskeerMigrationToolTest.cs (revision 7ad4fee36379181bfd053b3ea30dca613d776d71)
@@ -0,0 +1,233 @@
+// Copyright (C) Stichting Deltares 2018. 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.Collections.Generic;
+using Core.Common.TestUtil;
+using Migration.Console;
+using Migration.Console.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Util;
+using Riskeer.Migration.Core;
+using Riskeer.Migration.Core.TestUtil;
+
+namespace Application.Riskeer.Migration.Console.Test
+{
+ [TestFixture]
+ [Explicit("Migration Console tests are disabled.")]
+ public class RiskeerMigrationToolTest
+ {
+ private TestEnvironmentControl environmentControl;
+ private readonly TestDataPath testPath = TestDataPath.Ringtoets.Migration.Core;
+
+ [SetUp]
+ public void SetUp()
+ {
+ environmentControl = new TestEnvironmentControl();
+ EnvironmentControl.Instance = environmentControl;
+ }
+
+ [Test]
+ public void Main_NoArguments_WritesHelpToConsole()
+ {
+ // Setup
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ RiskeerMigrationTool.Main(new string[]
+ {});
+
+ // Assert
+ string consoleText = consoleOutput.GetConsoleOutput();
+ string expectedText = Environment.NewLine + GetConsoleFullDescription();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ public void Main_InvalidArguments_WritesHelpToConsoleWithErrorCode()
+ {
+ // Setup
+ string[] invalidCommand =
+ {
+ "0",
+ "1",
+ "2"
+ };
+
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // Call
+ RiskeerMigrationTool.Main(invalidCommand);
+
+ // Assert
+ string consoleText = consoleOutput.GetConsoleOutput();
+
+ string expectedText = Environment.NewLine
+ + $"{string.Join(" ", invalidCommand)} is geen geldige opdracht."
+ + Environment.NewLine + Environment.NewLine
+ + GetConsoleFullDescription();
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ [TestCaseSource(nameof(RingtoetsFilesToMigrate))]
+ public void GivenConsole_WhenVersionSupportedCall_ThenReturnedIfSupported(string file, string fileVersion, bool isSupported)
+ {
+ // Given
+ string sourceFilePath = TestHelper.GetTestDataPath(testPath, file);
+ string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ RiskeerMigrationTool.Main(new[]
+ {
+ sourceFilePath
+ });
+
+ // Then
+ string consoleText = consoleOutput.GetConsoleOutput();
+ string expectedText = isSupported
+ ? Environment.NewLine
+ + $@"Het projectbestand kan gemigreerd worden naar versie '{expectedVersion}'."
+ + Environment.NewLine
+ : Environment.NewLine
+ + $"Het migreren van een projectbestand met versie '{fileVersion}' naar versie '{expectedVersion}' is niet ondersteund."
+ + Environment.NewLine;
+
+ Assert.AreEqual(expectedText, consoleText);
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion()
+ {
+ // Given
+ string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationToolTest)}.{nameof(GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion)}");
+ string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ using (new FileDisposeHelper(targetFilePath))
+ {
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ // When
+ RiskeerMigrationTool.Main(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ // Then
+ string consoleText = consoleOutput.GetConsoleOutput();
+ string expected = Environment.NewLine
+ + $"Het projectbestand '{sourceFilePath}' is succesvol gemigreerd naar "
+ + $"'{targetFilePath}' (versie {expectedVersion})."
+ + Environment.NewLine;
+ Assert.AreEqual(expected, consoleText);
+ var toVersionedFile = new RingtoetsVersionedFile(targetFilePath);
+ Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion());
+ }
+ }
+
+ Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
+ }
+
+ [Test]
+ public void GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode()
+ {
+ // Given
+ string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationToolTest)}.{nameof(GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode)}");
+
+ using (var fileDisposeHelper = new FileDisposeHelper(targetFilePath))
+ using (var consoleOutput = new ConsoleOutput())
+ {
+ fileDisposeHelper.LockFiles();
+
+ // When
+ RiskeerMigrationTool.Main(new[]
+ {
+ sourceFilePath,
+ targetFilePath
+ });
+
+ // Then
+ string consoleText = consoleOutput.GetConsoleOutput();
+ StringAssert.StartsWith(Environment.NewLine
+ + "Het gemigreerde projectbestand is aangemaakt op '",
+ consoleText);
+ StringAssert.EndsWith($"', maar er is een onverwachte fout opgetreden tijdens het verplaatsen naar '{targetFilePath}'."
+ + Environment.NewLine
+ + "Het besturingssysteem geeft de volgende melding: " + Environment.NewLine
+ + $"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()
+ {
+ string currentDatabaseVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ 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 ({currentDatabaseVersion})."
+ + Environment.NewLine + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA -h" + Environment.NewLine
+ + "MIGRATIEHULPPROGRAMMA --help" + Environment.NewLine
+ + " Geeft deze informatie weer." + 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
+ + "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;
+ }
+
+ #region Test cases
+
+ private static IEnumerable RingtoetsFilesToMigrate()
+ {
+ string unsupportedProjectFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
+ var unsupportedVersionedFile = new RingtoetsVersionedFile(unsupportedProjectFilePath);
+ string unsupportedVersion = unsupportedVersionedFile.GetVersion();
+
+ string supportedProjectFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
+ var supportedVersionedFile = new RingtoetsVersionedFile(supportedProjectFilePath);
+ string supportedVersion = supportedVersionedFile.GetVersion();
+
+ yield return new TestCaseData(unsupportedProjectFilePath, unsupportedVersion, false).SetName("UnsupportedRingtoetsVersion");
+ yield return new TestCaseData(supportedProjectFilePath, supportedVersion, true).SetName("SupportedRingtoetsVersion");
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file