Esempio n. 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, @"");
        }
Esempio n. 2
0
        public void CombinedErrAndOutSimpleInterspersed()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedErrAndOut(TestApplications.SimpleInterspersedInfo)) {
                    result = process.Run();
                }
            });
            Assert.NotNull(result);
            Assert.Equal(result.ExitCode, 3);
            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.Null(result.FullStd);
            Assert.Null(result.FullError);
            Assert.Equal(result.FullOutput, @"abc
def
abc
def
abc
def
def
abc
aabbccddeeff");
        }
Esempio n. 3
0
        public void CombinedErrAndOutPlusTwoNumber()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedErrAndOut(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.Equal(result.FullOutput, @"Please enter a number...
878");

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithCombinedErrAndOut(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.Equal(result.FullOutput, @"Please enter a number...
Bad number");
        }
Esempio n. 4
0
        public void ExceptionAttachments()
        {
            var exception = new AssertionException("Testing {0}", 123);

            try {
                Assert.DoesNotThrow(() => { throw new ArgumentException(); }, exception);
            }
            catch (AssertionException e) {
                Assert.Equal(e.Message, "Testing 123");
            }
        }
        public void Equal()
        {
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer <object>));
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer));

            Assert.DoesNotThrow(() => Assert.Equal(1, 1));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(1, 0));
            Assert.DoesNotThrow(() => Assert.Equal(null, null));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, "hello"));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, 0));

            Assert.ThrowsExact <AssertionException>(() => Assert.Equal("000", "0000"));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new[] { 1, 2, 3 }));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2, 4 }, new[] { 1, 2, 3 }));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, null));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new List <int>()
            {
                1, 2
            }));
            Assert.DoesNotThrow(() => Assert.Equal(new[] { 1, 2, 3 }, new[] { 1, 2, 3 }));

            var arr1 = new[] {
                new[] { 1, 2 },
                new[] { 2, 1 },
            };

            Assert.DoesNotThrow(() => Assert.Equal(arr1, arr1));

            var arr2 = new[] {
                new[] { 2, 1 },
                new[] { 1, 2 },
            };

            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(arr1, arr2));

            arr2 = new[] {
                new[] { 1, 2 },
                new[] { 2, 1 },
            };
            Assert.DoesNotThrow(() => Assert.Equal(arr1, arr2));

            var enumImpl1 = new EnumerableImpl(1, 2);
            var enumImpl2 = new EnumerableImpl(2, 1);

            Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl1));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal(enumImpl1, enumImpl2));
            enumImpl2 = new EnumerableImpl(1, 2);
            Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl2));

            Assert.DoesNotThrow(() => Assert.Equal("abc", "ABC", StringComparer.InvariantCultureIgnoreCase));
            Assert.DoesNotThrow(() => Assert.Equal("abc" as object, "ABC" as object, StringComparer.InvariantCultureIgnoreCase));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc", "BBB", StringComparer.InvariantCultureIgnoreCase));
            Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc" as object, "BBB" as object, StringComparer.InvariantCultureIgnoreCase));
        }
Esempio n. 6
0
        public void SplitErrAndOutNoOutput()
        {
            ProcessResult result = null;

            Assert.DoesNotThrow(() => {
                using (var process = new ProcessSpawnerWithSplitErrAndOut(TestApplications.NoOutputInfo)) {
                    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.Null(result.FullOutput);
            Assert.NotNull(result.FullStd);
            Assert.NotNull(result.FullError);
            Assert.Equal(result.FullStd, @"");
            Assert.Equal(result.FullError, @"");
        }