Example #1
0
        public void TestOnOutputLines()
        {
            const int exitCode = 29;

            TestBuiltInCommandEnvironment environment = new TestBuiltInCommandEnvironment();

            Func <string[], int> testCommand = args =>
            {
                TextWriter outWriter = environment.GetConsoleOut();
                outWriter.Write("first");
                outWriter.WriteLine("second");
                outWriter.WriteLine("third");

                TextWriter errorWriter = environment.GetConsoleError();
                errorWriter.WriteLine("fourth");
                errorWriter.WriteLine("fifth");

                return(exitCode);
            };

            int onOutputLineCallCount = 0;
            int onErrorLineCallCount  = 0;

            CommandResult result = new BuiltInCommand("fakeCommand", Enumerable.Empty <string>(), testCommand, environment)
                                   .OnOutputLine(line =>
            {
                onOutputLineCallCount++;

                if (onOutputLineCallCount == 1)
                {
                    Assert.Equal($"firstsecond", line);
                }
                else
                {
                    Assert.Equal($"third", line);
                }
            })
                                   .OnErrorLine(line =>
            {
                onErrorLineCallCount++;

                if (onErrorLineCallCount == 1)
                {
                    Assert.Equal($"fourth", line);
                }
                else
                {
                    Assert.Equal($"fifth", line);
                }
            })
                                   .Execute();

            Assert.Equal(exitCode, result.ExitCode);
            Assert.Equal(2, onOutputLineCallCount);
            Assert.Equal(2, onErrorLineCallCount);
        }
        public void TestExecute()
        {
            Func<string[], int> testCommand = args => args.Length;
            string[] testCommandArgs = new[] { "1", "2" };

            var builtInCommand = new BuiltInCommand("fakeCommand", testCommandArgs, testCommand, new TestBuiltInCommandEnvironment());
            CommandResult result = builtInCommand.Execute();

            Assert.Equal(testCommandArgs.Length, result.ExitCode);
            Assert.Equal(new Muxer().MuxerPath, result.StartInfo.FileName);
            Assert.Equal("fakeCommand 1 2", result.StartInfo.Arguments);
        }
Example #3
0
        public void TestExecute()
        {
            Func <string[], int> testCommand = args => args.Length;

            string[] testCommandArgs = new[] { "1", "2" };

            var           builtInCommand = new BuiltInCommand("fakeCommand", testCommandArgs, testCommand, new TestBuiltInCommandEnvironment());
            CommandResult result         = builtInCommand.Execute();

            Assert.Equal(testCommandArgs.Length, result.ExitCode);
            Assert.Equal(new Muxer().MuxerPath, result.StartInfo.FileName);
            Assert.Equal("fakeCommand 1 2", result.StartInfo.Arguments);
        }
        public void TestOnOutputLines()
        {
            const int exitCode = 29;

            TestBuiltInCommandEnvironment environment = new TestBuiltInCommandEnvironment();

            Func<string[], int> testCommand = args =>
            {
                TextWriter outWriter = environment.GetConsoleOut();
                outWriter.Write("first");
                outWriter.WriteLine("second");
                outWriter.WriteLine("third");

                TextWriter errorWriter = environment.GetConsoleError();
                errorWriter.WriteLine("fourth");
                errorWriter.WriteLine("fifth");

                return exitCode;
            };

            int onOutputLineCallCount = 0;
            int onErrorLineCallCount = 0;

            CommandResult result = new BuiltInCommand("fakeCommand", Enumerable.Empty<string>(), testCommand, environment)
                .OnOutputLine(line =>
                {
                    onOutputLineCallCount++;

                    if (onOutputLineCallCount == 1)
                    {
                        Assert.Equal($"firstsecond", line);
                    }
                    else
                    {
                        Assert.Equal($"third", line);
                    }
                })
                .OnErrorLine(line =>
                {
                    onErrorLineCallCount++;

                    if (onErrorLineCallCount == 1)
                    {
                        Assert.Equal($"fourth", line);
                    }
                    else
                    {
                        Assert.Equal($"fifth", line);
                    }
                })
                .Execute();

            Assert.Equal(exitCode, result.ExitCode);
            Assert.Equal(2, onOutputLineCallCount);
            Assert.Equal(2, onErrorLineCallCount);
        }