public void GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode() { // Given string sourceFilePath = ProjectMigrationTestHelper.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); } }
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); } }
public void GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion() { // Given string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationConsoleTest)}.{nameof(GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion)}"); var console = new RiskeerMigrationConsole(); string expectedVersion = ProjectVersionHelper.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 ProjectVersionedFile(targetFilePath); Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion()); } } Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled); }
public void GivenConsole_WhenVersionSupportedCall_ThenReturnedIfSupported(string file, string fileVersion, bool isSupported) { // Given string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Migration.Core, file); var console = new RiskeerMigrationConsole(); string expectedVersion = ProjectVersionHelper.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); } }
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); } }
public void Constructor_ExpectedProperties() { // Call var console = new RiskeerMigrationConsole(); // Assert Assert.IsInstanceOf <ConsoleBase>(console); }
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); } }
/// <summary> /// Main migration application. /// </summary> /// <param name="args">Arguments </param> /// <remarks>Accepted commands:<list type="bullet"> /// <item>--help Shows help menu,</item> /// <item>--supported Returns if the database file is supported,</item> /// <item>--migrate Migrates the database file to a newer version.</item> /// </list></remarks> public static void Main(string[] args) { var riskeerMigrationConsole = new RiskeerMigrationConsole(); riskeerMigrationConsole.ExecuteConsoleTool(args); }