public void GivenConsole_WhenVersionSupportedCall_ThenReturnedIfSupported(string file, string fileVersion, bool isSupported) { // Given string sourceFilePath = TestHelper.GetTestDataPath(testPath, file); string expectedVersion = ProjectVersionHelper.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); } }
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); } }
public void GivenConsole_WhenMigrateCalledUnableToSaveTarget_ThenExitWithErrorCode() { // Given string sourceFilePath = ProjectMigrationTestHelper.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); }
public void GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion() { // Given string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); string targetFilePath = TestHelper.GetScratchPadPath($"{nameof(RiskeerMigrationToolTest)}.{nameof(GivenConsole_WhenMigrateCalledWithArguments_MigratesToNewVersion)}"); string expectedVersion = ProjectVersionHelper.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 ProjectVersionedFile(targetFilePath); Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion()); } } Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled); }
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); } }