Пример #1
0
 /// <summary>
 /// Performs reference equality checking between your actual and the provided expected value
 /// </summary>
 /// <param name="be">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
 /// <typeparam name="T">Type of the object being tested</typeparam>
 public static void Be <T>(
     this ITo <T> be,
     object expected,
     Func <string> customMessageGenerator)
 {
     be.AddMatcher(CreateRefEqualMatcherFor <T>(expected, customMessageGenerator));
 }
Пример #2
0
        public static IMore <string> Match(
            this ITo <string> to,
            string expected)
        {
            // sql testing shouldn't care about case or (too much) about
            // whitespace -- all whitespace is equal
            return(to.AddMatcher(actual =>
            {
                var normalisedActual = Normalise(actual);
                var normalisedExpected = Normalise(expected);
                var passed = normalisedActual == normalisedExpected;
                return new MatcherResult(
                    passed,
                    () => $@"Expected
{actual}
to match (normalised)
{expected}

normalised values:
actual:
{normalisedActual}
expected
{normalisedExpected}"
                    );
            }));
        }
 /// <summary>
 /// Match the value under test with a simple Func which takes in your value
 /// and returns true if the test should pass.
 /// </summary>
 /// <param name="continuation">Continuation to act on</param>
 /// <param name="test">Func to test the original value with</param>
 /// <param name="customMessageGenerator">Generates a custom message to include in the result upon failure</param>
 /// <typeparam name="T"></typeparam>
 public static void Match <T>(
     this ITo <T> continuation,
     Func <T, bool> test,
     Func <string> customMessageGenerator
     )
 {
     continuation.AddMatcher(MatchMatcherFor(test, customMessageGenerator));
 }
Пример #4
0
 /// <summary>
 /// Expects a file or folder to exist at the provided path
 /// </summary>
 /// <param name="to"></param>
 /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
 /// <returns></returns>
 public static IStringMore Exist(
     this ITo <string> to,
     Func <string> customMessageGenerator)
 {
     to.AddMatcher(actual =>
                   ResolveFileResultFor(actual, customMessageGenerator)
                   );
     return(to.More());
 }
 /// <summary>
 /// Performs equality checking -- the end of .To.Equal()
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="customMessageGenerator">Custom message to include when failing</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static IMore <T> Equal <T>(
     this ITo <T> continuation,
     T expected,
     Func <string> customMessageGenerator
     )
 {
     return(continuation.AddMatcher(
                GenerateEqualityMatcherFor(expected, customMessageGenerator)
                ));
 }
Пример #6
0
 /// <summary>
 /// Performs equality checking -- the end of .To.Equal()
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="customMessageGenerator">Custom message to add into failure messages</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static void Equal <T>(
     this ITo <T> continuation,
     T?expected,
     Func <string> customMessageGenerator
     ) where T : struct
 {
     continuation.AddMatcher(
         GenerateNullableEqualityMatcherFor(expected, customMessageGenerator)
         );
 }
Пример #7
0
 public static void Match(
     this ITo <bitsplat.History.HistoryItem> to,
     bitsplat.History.HistoryItem expected)
 {
     to.AddMatcher(actual =>
     {
         var passed = actual.Path == expected.Path &&
                      actual.Size == expected.Size &&
                      actual.Created >= expected.Created;
         return(new MatcherResult(
                    passed,
                    () => $"Expected {actual.Stringify()} {passed.AsNot()}to match {expected.Stringify()}"
                    ));
     });
 }
 internal static IStringMore LookLikeUrl(
     this ITo <string> to
     )
 {
     to.AddMatcher(actual =>
     {
         var proto  = "://";
         var passed = !string.IsNullOrWhiteSpace(actual) &&
                      actual.Contains(proto) &&
                      !actual.StartsWith(proto) &&
                      !actual.EndsWith("://");
         return(new MatcherResult(
                    passed,
                    $"Expected \"{actual}\" {passed.AsNot()}to look like an url"
                    ));
     });
     return(to.More());
 }
 internal static IStringMore LookLikeEmailAddress(
     this ITo <string> to
     )
 {
     to.AddMatcher(email =>
     {
         var passed = !string.IsNullOrWhiteSpace(email) &&
                      email.IndexOf("@", StringComparison.Ordinal) > 0 &&
                      email.IndexOf("@", StringComparison.Ordinal) < email.Length - 2 &&
                      email.IndexOf(".", StringComparison.Ordinal) > 0 &&
                      email.IndexOf(".", StringComparison.Ordinal) < email.Length - 2;
         return(new MatcherResult(
                    passed,
                    $"Expected \"{email}\" {passed.AsNot()}to look like an email address"
                    ));
     });
     return(to.More());
 }