public async Task ErrorHandling()
        {
            using (var consoleIn = new StringReader(string.Empty))
            {
                using (var consoleError = new StringWriter())
                {
                    SetConsoleIn(consoleIn);
                    Console.SetError(consoleError);
                    int exitCode = await ModularInput.RunAsync <TestScript>(new string[] { });

                    // There will be an exception due to missing input definition in
                    // (redirected) console stdin.
                    var error = consoleError.ToString();

                    // Verify that an exception is logged with level FATAL.
                    Assert.Contains("FATAL Script.Run: Unhandled exception:", error);

                    // Verify that the exception is what we expect.
                    Assert.Contains("Root element is missing", error);

                    // Verify that an info level message is logged properly.
                    Assert.Contains("INFO Script.Run: Reading input definition", error);

                    // Verify that the logged exception does not span more than one line
                    // Splunk breaks up events using new lines for splunkd log.
                    var lines = error.Split(
                        new[] { Environment.NewLine },
                        StringSplitOptions.RemoveEmptyEntries);

                    Assert.Equal(2, lines.Length);
                    Assert.NotEqual(0, exitCode);
                }
            }
        }
        public async Task OutputScheme()
        {
            using (var consoleOut = new StringWriter())
            {
                Console.SetOut(consoleOut);
                await ModularInput.RunAsync <TestScript>(new[] { "--scheme" });

                AssertEqualWithExpectedFile(SchemeFilePath, consoleOut.ToString());
            }
        }
        public async Task ExternalValidation()
        {
            using (var consoleIn = ReadFileFromDataFolderAsReader(ValidationItemsFilePath))
                using (var consoleOut = new StringWriter())
                {
                    SetConsoleIn(consoleIn);
                    Console.SetOut(consoleOut);

                    int exitCode = await ModularInput.RunAsync <TestScript>(new[] { "--validate-arguments" });

                    AssertEqualWithExpectedFile(ValidationErrorMessageFilePath, consoleOut.ToString());
                    Assert.NotEqual(0, exitCode);
                }
        }
        public async Task StreamEvents()
        {
            using (var consoleIn = ReadFileFromDataFolderAsReader(InputDefinitionFilePath))
            {
                using (var consoleOut = new StringWriter())
                {
                    SetConsoleIn(consoleIn);
                    Console.SetOut(consoleOut);
                    await ModularInput.RunAsync <TestScript>(new string[] { });

                    AssertEqualWithExpectedFile(EventsFilePath, consoleOut.ToString());
                }
            }
        }