Пример #1
0
        public void RunRoundingEdgeCase()
        {
            double d = 3;
            int i = 2;

            PAssert.IsTrue(() => 4.5 == d + 3 / i);
        }
Пример #2
0
        public void EqualsButNotOperatorEquals()
        {
            var t1 = new Tuple<string>("foo");
            var t2 = new Tuple<string>("foo");

            PAssert.IsTrue(() => t1 == t2);
        }
Пример #3
0
 public void RunComplexExpression()
 {
     int x = 11;
     int y = 6;
     DateTime d = new DateTime(2010, 3, 1);
     PAssert.IsTrue(() => x + 5 == d.Month * y);
 }
Пример #4
0
        public void Should_assert_on_the_thrown_exception()
        {
            var expectedException = new Exception("broken");

            var actualException = PAssert.Throws <Exception>(() => MethodThatDoesThrow(expectedException), x => x.Message == "broken");

            Assert.That(actualException, Is.EqualTo(expectedException));
        }
Пример #5
0
        public async Task Should_return_the_thrown_exception_when_async()
        {
            var expectedException = new Exception();

            var actualException = await PAssert.Throws <Exception>(async() => await AsyncMethodThatDoesThrow(expectedException));

            Assert.That(actualException, Is.EqualTo(expectedException));
        }
Пример #6
0
        public async Task Should_assert_on_the_thrown_exception_when_async()
        {
            var expectedException = new Exception("broken");

            var actualException = await PAssert.Throws <Exception>(async() => await AsyncMethodThatDoesThrow(expectedException), x => x.Message == "broken");

            Assert.That(actualException, Is.EqualTo(expectedException));
        }
Пример #7
0
        public void PrintingEnumerablesWithNulls()
        {
            var list = new List <int?> {
                1, 2, null, 4, 5
            };

            PAssert.IsTrue(() => list.Sum() == null);
        }
Пример #8
0
        public void Should_return_the_thrown_exception()
        {
            var expectedException = new Exception();

            var actualException = PAssert.Throws <Exception>(() => MethodThatDoesThrow(expectedException));

            Assert.That(actualException, Is.EqualTo(expectedException));
        }
Пример #9
0
        public void RunComplexExpression3()
        {
            List <int> l = new List <int> {
                1, 2, 3
            };
            bool b = false;

            PAssert.IsTrue(() => l[2].ToString() == (b ? "three" : "four"));
        }
Пример #10
0
        public void SequenceEqualButNotOperatorEquals()
        {
            object list = new List <int> {
                1, 2, 3
            };
            object array = new[] { 1, 2, 3 };

            PAssert.IsTrue(() => list == array);
        }
Пример #11
0
        public void Should_fail_when_expression_does_not_throw_an_exception()
        {
            try
            {
                PAssert.Throws <Exception>(() => MethodThatDoesNotThrowAnException());
            }
            catch
            {
                return;
            }

            throw new Exception("Expected throws assertion to fail.");
        }
Пример #12
0
        public void Should_fail_if_thrown_exception_is_of_wrong_type()
        {
            try
            {
                PAssert.Throws <ArgumentException>(() => MethodThatDoesThrow(new NullReferenceException()));
            }
            catch
            {
                return;
            }

            throw new Exception("Expected throws assertion to fail.");
        }
Пример #13
0
        public void Should_not_block_when_async()
        {
            var sw = new Stopwatch();

            sw.Start();
            // no await here:
            var assert = PAssert.Throws <Exception>(async() =>
            {
                await Task.Delay(TimeSpan.FromSeconds(10));
                throw new Exception("uncaught");
            });

            sw.Stop();

            Assert.That(sw.Elapsed, Is.LessThan(TimeSpan.FromSeconds(1)));
        }
Пример #14
0
 public void RunComplexExpressionWithStaticField()
 {
     int y = 6;
     DateTime d = new DateTime(2010, 3, 1);
     PAssert.IsTrue(() => field + 5 == d.Month * y);
 }
Пример #15
0
        public void PrintingComplexLinqExpressionStatements()
        {
            var list = Enumerable.Range(0, 5);

            PAssert.IsTrue(() => (from x in list from y in list where x > y select x + "," + y).Count() == 0);
        }
Пример #16
0
        public void PrintingLinqExpressionStatements()
        {
            var list = Enumerable.Range(0, 150);

            PAssert.IsTrue(() => (from l in list where l % 2 == 0 select l).Sum() == 0);
        }
Пример #17
0
        public void PrintingLinqStatements()
        {
            var list = Enumerable.Range(0, 150);

            PAssert.IsTrue(() => list.Where(x => x % 2 == 0).Sum() == 0);
        }
Пример #18
0
        public void PrintingIsTest()
        {
            var b = new object();

            PAssert.IsTrue(() => b is string);
        }
Пример #19
0
 public void RunTypeOfExpression()
 {
     int x = 1;
     PAssert.IsTrue(() => x.GetType() == typeof(string));
 }
Пример #20
0
 public void RunComplexExpression2()
 {
     string x = " lalalaa ";
     int i = 10;
     PAssert.IsTrue(() => x.Trim().Length == Math.Max(4, new int[] { 5, 4, i / 3, 2 }[0]));
 }
Пример #21
0
 public void PrintingDelegateInvocation()
 {
     var array = new int[] { 1, 2, 3 };
     PAssert.IsTrue(() => array.Any(x => x > 3));
 }
Пример #22
0
 public void PrintingDelegateMethodGroupInvocation()
 {
     var array = new int[] { 1, 2, 3 };
     PAssert.IsTrue(() => array.Any(GreaterThan3));
 }
Пример #23
0
 public void Should_succeed_when_expression_does_throw_an_exception()
 {
     PAssert.Throws <Exception>(() => MethodThatDoesThrow(new Exception()));
 }
Пример #24
0
        public void PrintingUnaryNot()
        {
            var b = true;

            PAssert.IsTrue(() => !b);
        }
Пример #25
0
        public void PrintingUnaryNegate()
        {
            var b = 5;

            PAssert.IsTrue(() => - b == 0);
        }
Пример #26
0
 public void RunStringCompare()
 {
     string s = "hello, bobby";
     Tuple<string> t = new Tuple<string>("hello, Bobby");
     PAssert.IsTrue(() => s == t.Item1);
 }
Пример #27
0
 public async Task Should_succeed_when_async_expression_does_throw_exception()
 {
     await PAssert.Throws <Exception>(async() => await AsyncMethodThatDoesThrow(new Exception()));
 }
Пример #28
0
 public void PrintingNewArrayTest()
 {
     var array = new int[]{1,2,3};
     PAssert.IsTrue(() => array.Equals(new[]{4,5,6}));
 }