Ejemplo n.º 1
0
        public void ExecuteConsoleTool_ThrowsExceptionWithoutInnerException_WritesErrorWithErrorCode()
        {
            // Setup
            const string command          = "invalid command";
            const string exceptionMessage = "I was told to be thrown.";

            string[] commandArgs =
            {
                command
            };
            var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);

            using (var consoleOutput = new ConsoleOutput())
            {
                consoleBase.ExceptionToBeThrown = new CriticalMigrationException(exceptionMessage);

                // Call
                consoleBase.SimpleExecuteConsoleTool(commandArgs);

                // Assert
                string expectedtext = Environment.NewLine + exceptionMessage + Environment.NewLine
                                      + Environment.NewLine + GetConsoleFullDescription();
                string consoleText = consoleOutput.GetConsoleOutput();
                Assert.AreEqual(expectedtext, consoleText);

                Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
                Assert.AreEqual(ErrorCode.ErrorBadCommand, environmentControl.ErrorCodeCalled);
            }
        }
Ejemplo n.º 2
0
        public void ExecuteConsoleTool_ThrowsExceptionWithInnerException_WritesErrorsWithErrorCode()
        {
            // Setup
            const string command               = "invalid command";
            const string exceptionMessage      = "I was told to be thrown.";
            const string innerExceptionMessage = "inner exception.";

            string[] commandArgs =
            {
                command
            };
            var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);

            using (var consoleOutput = new ConsoleOutput())
            {
                consoleBase.ExceptionToBeThrown = new Exception(exceptionMessage, new Exception(innerExceptionMessage));

                // Call
                consoleBase.SimpleExecuteConsoleTool(commandArgs);

                // Assert
                string expectedtext = Environment.NewLine + exceptionMessage + Environment.NewLine
                                      + "Het besturingssysteem geeft de volgende melding: " + Environment.NewLine
                                      + $"{innerExceptionMessage}"
                                      + Environment.NewLine + Environment.NewLine
                                      + GetConsoleFullDescription();
                string consoleText = consoleOutput.GetConsoleOutput();
                Assert.AreEqual(expectedtext, consoleText);

                Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
                Assert.AreEqual(ErrorCode.ErrorInvalidCommandLine, environmentControl.ErrorCodeCalled);
            }
        }
Ejemplo n.º 3
0
        public void DisplayCommands_WritesNoCommandsToConsole()
        {
            // Setup
            var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);

            using (var consoleOutput = new ConsoleOutput())
            {
                // Call
                consoleBase.WriteDisplayCommands();

                // Assert
                string consoleText = consoleOutput.GetConsoleOutput();
                Assert.IsEmpty(consoleText);
                Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
            }
        }
Ejemplo n.º 4
0
        public void ExecuteConsoleTool_ArgsNull_WritesAllCommandsToConsole()
        {
            // Setup
            var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);

            using (var consoleOutput = new ConsoleOutput())
            {
                // Call
                consoleBase.SimpleExecuteConsoleTool(null);

                // Assert
                string consoleText  = consoleOutput.GetConsoleOutput();
                string expectedText = Environment.NewLine + GetConsoleFullDescription();
                Assert.AreEqual(expectedText, consoleText);
                Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
            }
        }
Ejemplo n.º 5
0
        public void ExecuteConsoleTool_ArgsIsInvalid_CallsExecuteCommand()
        {
            // Setup
            const string command = "invalid command";

            string[] commandArgs =
            {
                command
            };
            var consoleBase = new SimpleConsoleBase(applicationName, applicationDescription);

            using (var consoleOutput = new ConsoleOutput())
            {
                // Call
                consoleBase.SimpleExecuteConsoleTool(commandArgs);

                // Assert
                Assert.AreEqual(Environment.NewLine, consoleOutput.GetConsoleOutput());
                Assert.AreEqual(commandArgs, consoleBase.ExecuteCommandArguments);
                Assert.AreEqual(ErrorCode.ErrorSuccess, environmentControl.ErrorCodeCalled);
            }
        }