示例#1
0
        public void CombinedAndSplitErrAndOutNakedInput()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.NakedInput)) {
                    process.OnInputRequested += (buf, writer) => {
                        if (!string.IsNullOrEmpty(buf) && buf != "acb876")
                        {
                            Assert.Fail();
                        }
                        writer.WriteLine("acb876");
                        return(ProcessInputHandleResult.Handled);
                    };

                    result = process.Run();
                }
            });
            Assert.NotNull(result);
            Assert.NotNull(result.FullOutput);
            Assert.NotNull(result.FullStd);
            Assert.NotNull(result.FullError);
            Assert.Equal(result.FullOutput, @"acb876");
            Assert.Equal(result.FullStd, @"acb876");
            Assert.Equal(result.FullError, @"");
        }
示例#2
0
        public void CombinedAndSplitErrAndOutBlankLinesInterspersed()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.BlankLinesInterspersedInfo)) {
                    result = process.Run();
                }
            });
            Assert.NotNull(result);
            Assert.Equal(result.ExitCode, 0);
            Assert.GreaterThan(result.PeakPagedMemorySize, 0);
            Assert.GreaterThan(result.PeakVirtualMemorySize, 0);
            Assert.GreaterThan(result.PeakWorkingSet, 0);
            Assert.NotEqual(result.StartTime, DateTime.MinValue);
            Assert.NotEqual(result.ExitTime, DateTime.MinValue);
            Assert.GreaterThan(result.ExitTime - result.StartTime, TimeSpan.Zero);
            Assert.NotNull(result.FullOutput);
            Assert.NotNull(result.FullStd);
            Assert.NotNull(result.FullError);
            Assert.Equal(result.FullOutput, @"abc

def

abc
def

abc
def
def

abc");
            Assert.Equal(result.FullStd, @"def

def

def
def");
            Assert.Equal(result.FullError, @"abc

abc
abc

abc");
        }
示例#3
0
        public void CombinedAndSplitErrAndOutPlusTwoNumber()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.PlusTwoNumberInfo)) {
                    process.OnInputRequested += (buf, writer) => {
                        if (string.IsNullOrEmpty(buf))
                        {
                            return(ProcessInputHandleResult.Ignored);
                        }
                        if (buf == "878")
                        {
                            return(ProcessInputHandleResult.Ignored);
                        }
                        if (buf != "Please enter a number...")
                        {
                            Assert.Fail();
                            return(ProcessInputHandleResult.Ignored);
                        }
                        writer.WriteLine("876");
                        return(ProcessInputHandleResult.Handled);
                    };

                    result = process.Run();
                }
            });
            Assert.NotNull(result);
            Assert.NotNull(result.FullOutput);
            Assert.NotNull(result.FullStd);
            Assert.NotNull(result.FullError);
            Assert.Equal(result.FullOutput, @"Please enter a number...
878");
            Assert.Equal(result.FullStd, @"Please enter a number...
878");
            Assert.Equal(result.FullError, @"");

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.PlusTwoNumberInfo)) {
                    process.OnInputRequested += (buf, writer) => {
                        if (string.IsNullOrEmpty(buf))
                        {
                            return(ProcessInputHandleResult.Ignored);
                        }
                        if (buf == "Bad number")
                        {
                            return(ProcessInputHandleResult.Ignored);
                        }
                        if (buf != "Please enter a number...")
                        {
                            Assert.Fail();
                            return(ProcessInputHandleResult.Ignored);
                        }
                        writer.WriteLine("abc");
                        return(ProcessInputHandleResult.Handled);
                    };

                    result = process.Run();
                }
            });
            Assert.NotNull(result);
            Assert.NotNull(result.FullOutput);
            Assert.NotNull(result.FullStd);
            Assert.NotNull(result.FullError);
            Assert.Equal(result.FullOutput, @"Please enter a number...
Bad number");
            Assert.Equal(result.FullStd, @"Please enter a number...");
            Assert.Equal(result.FullError, @"Bad number");
        }