예제 #1
0
 private static void TestBoolean(
     IBe <bool> expectation,
     bool expected,
     Func <string> message
     )
 {
     expectation.AddMatcher(TruthTestFor(expected, message));
 }
예제 #2
0
 /// <summary>
 /// Tests if a boolean value is True
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="customMessageGenerator">Generates a custom message to include on failure</param>
 public static void True(
     this IBe <bool?> continuation,
     Func <string> customMessageGenerator
     )
 {
     // ReSharper disable once ConditionIsAlwaysTrueOrFalse
     continuation.AddMatcher(TruthTestFor(true as bool?, customMessageGenerator));
 }
예제 #3
0
 public static void Falsey(this IBe <long> be)
 {
     be.AddMatcher(
         actual =>
     {
         var passed = actual == 0;
         return(new MatcherResult(
                    passed,
                    () => $"Expected {actual} {passed.AsNot()}to be falsey"));
     });
 }
예제 #4
0
 public static void Null <T>(this IBe <T> continuation, string customMessage)
 {
     continuation.AddMatcher(actual =>
     {
         var passed = actual == null;
         return(new MatcherResult(
                    passed,
                    FinalMessageFor(
                        passed
                     ? "Expected not to get null"
                     : $"Expected null but got {Quote(actual)}",
                        customMessage)
                    ));
     });
 }
        internal static IStringMore AllNumeric(
            this IBe <string> be
            )
        {
            be.AddMatcher(actual =>
            {
                var passed = actual.All(c => "0123456789".Contains(c));
                return(new MatcherResult(
                           passed,
                           $"Expected \"{actual}\" {passed.AsNot()}to be all numeric"
                           ));
            });

            return(be.More());
        }
예제 #6
0
 /// <summary>
 /// Asserts that a string is alpha
 /// </summary>
 /// <param name="be"></param>
 /// <param name="customMessageGenerator"></param>
 /// <returns></returns>
 public static IStringMore Alpha(
     this IBe <string> be,
     Func <string> customMessageGenerator)
 {
     be.AddMatcher(actual =>
     {
         var passed = actual != null &&
                      actual.All(c => c.IsAlpha());
         return(new MatcherResult(
                    passed,
                    FinalMessageFor(
                        () => $"Expected {actual.Stringify()} {passed.AsNot()}to be alpha",
                        customMessageGenerator)
                    ));
     });
     return(be.More());
 }
 /// <summary>
 /// Tests if a string is empty, with a provided custom error message
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="customMessageGenerator">Generates a custom message to include when failing</param>
 public static void Empty(
     this IBe <string> continuation,
     Func <string> customMessageGenerator)
 {
     continuation.AddMatcher(
         actual =>
     {
         var passed = actual == "";
         return(new MatcherResult(
                    passed,
                    FinalMessageFor(
                        () => passed
                               ? new[] { "Expected not to be empty" }
                               : new[] { "Expected empty string but got", Quote(actual) },
                        customMessageGenerator)
                    ));
     });
 }
 /// <summary>
 /// Tests if a value is null
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="customMessageGenerator">Generates a custom message to include when failing</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static IMore <T> Null <T>(
     this IBe <T> continuation,
     Func <string> customMessageGenerator
     )
 {
     continuation.AddMatcher(
         actual =>
     {
         var passed = actual == null;
         return(new MatcherResult(
                    passed,
                    FinalMessageFor(
                        () => passed
                               ? new[] { "Expected not to get null" }
                               : new[] { "Expected null but got", Quote(actual) },
                        customMessageGenerator)
                    ));
     });
     return(continuation.More());
 }
예제 #9
0
 /// <summary>
 /// Tests if a boolean value is False
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 public static void False(this IBe <bool> continuation)
 {
     continuation.AddMatcher(TruthTestFor(false, null));
 }
예제 #10
0
 /// <summary>
 /// Tests if a boolean value is False
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="customMessageGenerator">Generats a custom message to include on failure</param>
 public static void False(
     this IBe <bool> continuation,
     Func <string> customMessageGenerator)
 {
     continuation.AddMatcher(TruthTestFor(false, customMessageGenerator));
 }
예제 #11
0
 public static void False(this IBe <bool?> expectation, string message)
 {
     expectation.AddMatcher(TruthTestFor(false as bool?, message));
 }
예제 #12
0
 public static void False(this IBe <bool?> expectation)
 {
     expectation.AddMatcher(TruthTestFor(false as bool?, null));
 }