public static DateTime Equal(this IShould <DateTime> should, DateTime expected, TimeSpan tolerance)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, tolerance),
                (t, a) => a.AreNotEqual(expected, t, tolerance)
                ));
 }
 public static double Equal(this IShould <double> should, double expected, double tolerance)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, tolerance),
                (t, a) => a.AreNotEqual(expected, t, tolerance)
                ));
 }
 public static DateTime Equal(this IShould <DateTime> should, DateTime expected, DatePrecision precision)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, precision),
                (t, a) => a.AreNotEqual(expected, t, precision)
                ));
 }
示例#4
0
        public static Invoker Throw(this IShould <Invoker> should, Exception error)
        {
            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoExceptionInstanceMessage(error));
                }

                if (!result.Error.Equals(error))
                {
                    a.Fail(AssertionMessages.NoExceptionInstanceMessage(error, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (error.Equals(result.Error))
                {
                    a.Fail(AssertionMessages.ExceptionInstanceMessage(error));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
示例#5
0
        public static Invoker Throw <TException>(this IShould <Invoker> should)
        {
            var exceptionType = typeof(TException);

            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoDerivedExceptionMessage(exceptionType));
                }

                if (!(result.Error is TException))
                {
                    a.Fail(AssertionMessages.NoDerivedExceptionMessage(exceptionType, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error is TException)
                {
                    a.Fail(AssertionMessages.DerivedExceptionMessage(exceptionType));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
示例#6
0
        public static Invoker Throw(this IShould <Invoker> should, Type exceptionType)
        {
            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoExactExceptionMessage(exceptionType));
                }

                if (result.Error.GetType() != exceptionType)
                {
                    a.Fail(AssertionMessages.NoExactExceptionMessage(exceptionType, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (exceptionType == result.Error.GetType())
                {
                    a.Fail(AssertionMessages.ExactExceptionMessage(exceptionType));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
示例#7
0
 public IEnumerable <T> Any(Func <T, bool> predicate)
 {
     return(should.Apply(
                (t, a) =>
     {
         if (t.Any(predicate) == false)
         {
             a.Fail("Expecting at least 1 matching item in list.  Found 0.");
         }
     },
                (t, a) =>
     {
         if (t.Any(predicate))
         {
             a.Fail("Expecting 0 matching item in list.  Found {0}.", t.Count());
         }
     }));
 }
示例#8
0
 public static string Contain(this IShould <string> should, string expectedSubstring)
 {
     return(should.Apply(
                (t, a) => a.IsSubstringOf(t, expectedSubstring),
                (t, a) =>
     {
         if (t.Contains(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to not contain '{1}', but it did.", t, expectedSubstring);
         }
     }));
 }
示例#9
0
 public static string EndWith(this IShould <string> should, string expectedSubstring)
 {
     return(should.Apply(
                (t, a) =>
     {
         if (!t.EndsWith(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to end with '{1}', but it did not.", t, expectedSubstring);
         }
     },
                (t, a) =>
     {
         if (t.EndsWith(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to not end with '{1}', but it did.", t, expectedSubstring);
         }
     }));
 }
示例#10
0
 public IEnumerable <T> Exactly(int number, Func <T, bool> predicate)
 {
     return(_should.Apply((enumerable, assertProvider) =>
     {
         var num = enumerable.Where(predicate).Count();
         if (num == number)
         {
             return;
         }
         assertProvider.Fail($"Expecting {number} matching item in list. Found {num}.");
     }, (enumerable, assertProvider) =>
     {
         var num = enumerable.Where(predicate).Count();
         if (num != number)
         {
             return;
         }
         assertProvider.Fail($"Expecting other than {number} matching item in list. Found {num}.");
     }));
 }
示例#11
0
 public static TTarget IsNull <TTarget>(IShould <TTarget> should)
 {
     return(should.Apply(
                (t, a) => a.IsNull(t),
                (t, a) => a.IsNotNull(t)));
 }
示例#12
0
 public static TTarget LessThanOrEqual <TTarget>(IShould <TTarget> should, TTarget value, IComparer <TTarget> comparer)
 {
     return(should.Apply(
                (t, a) => a.LessThanOrEqual(t, value, comparer),
                (t, a) => a.GreaterThan(t, value, comparer)));
 }
示例#13
0
 public static TTarget LessThan <TTarget>(IShould <TTarget> should, TTarget value)
 {
     return(should.Apply(
                (t, a) => a.LessThan(t, value),
                (t, a) => a.GreaterThanOrEqual(t, value)));
 }
示例#14
0
 public IEnumerable <T> Exactly(int expectedCount)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expectedCount, t.Count()),
                (t, a) => a.AreNotEqual(expectedCount, t.Count())));
 }