Esempio n. 1
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>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static void Equal <T>(
     this ITo <T> continuation,
     T?expected
     ) where T : struct
 {
     continuation.Equal(expected, NULL_STRING);
 }
Esempio n. 2
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>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static void Equal <T>(
     this ITo <T> continuation,
     T expected
     )
 {
     continuation.Equal(expected, NULL_STRING);
 }
 /// <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="customMessage">Custom message to add to failure messages</param>
 /// <typeparam name="T">Type of the object being tested</typeparam>
 public static IMore <T> Be <T>(
     this ITo <T> be,
     object expected,
     string customMessage)
 {
     return(be.Be(expected, () => customMessage));
 }
Esempio n. 4
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="expected">Interface type which should be implemented</param>
 /// <returns></returns>
 public static IMore <Type> Implement(
     this ITo <Type> to,
     Type expected
     )
 {
     return(to.Implement(expected, NULL_STRING));
 }
Esempio n. 5
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
 /// <typeparam name="TBase">Interface type to look for</typeparam>
 /// <returns></returns>
 public static IMore <Type> Inherit <TBase>(
     this ITo <Type> to,
     Func <string> customMessageGenerator
     )
 {
     return(to.AddInheritsMatcher <TBase>(customMessageGenerator));
 }
Esempio n. 6
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}"
                    );
            }));
        }
Esempio n. 7
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <typeparam name="TBase">Interface type to look for</typeparam>
 /// <returns></returns>
 public static IMore <Type> Inherit <TBase>(
     this ITo <Type> to,
     string customMessage
     )
 {
     return(to.AddInheritsMatcher <TBase>(() => customMessage));
 }
 /// <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>
 /// <typeparam name="T"></typeparam>
 public static void Match <T>(
     this ITo <T> continuation,
     Func <T, bool> test
     )
 {
     continuation.Match(test, NULL_STRING);
 }
Esempio n. 9
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <typeparam name="TInterface">Interface type to look for</typeparam>
 /// <returns></returns>
 public static IMore <Type> Implement <TInterface>(
     this ITo <Type> to,
     string customMessage
     )
 {
     return(to.AddImplementsMatcher <TInterface>(() => customMessage));
 }
Esempio n. 10
0
 /// <summary>
 /// Tests whether the Actual string is matched by the given Regex
 /// </summary>
 /// <param name="matched">Continuation to operate on</param>
 /// <param name="regex">Regex string to match with</param>
 /// <returns>More continuation for Actual string</returns>
 public static IStringMore Match(
     this ITo <string> matched,
     string regex
     )
 {
     return(matched.Match(regex, NULL_STRING));
 }
 /// <summary>
 /// Performs equality checking -- the end of .To.Equal()
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static IMore <T> Equal <T>(
     this ITo <T> continuation,
     T?expected
     ) where T : struct
 {
     return(continuation.Equal(expected, NULL_STRING));
 }
 /// <summary>
 /// Performs equality checking -- the end of .To.Equal()
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static IMore <T> Equal <T>(
     this ITo <T> continuation,
     T expected
     )
 {
     return(continuation.Equal(expected, NULL_STRING));
 }
Esempio n. 13
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));
 }
Esempio n. 14
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="customMessage">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,
     string customMessage)
 {
     be.Be(expected, () => customMessage);
 }
 public static void Match <T>(
     this ITo <T> continuation,
     Func <T, bool> test
     )
 {
     continuation.Match(test, null);
 }
Esempio n. 16
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="expected">Interface type which should be implemented</param>
 /// <param name="customMessageGenerator">Custom message to add to failure messages</param>
 /// <returns></returns>
 public static IMore <Type> Implement(
     this ITo <Type> to,
     Type expected,
     Func <string> customMessageGenerator
     )
 {
     return(AddImplementsMatcher(to, expected, customMessageGenerator));
 }
Esempio n. 17
0
 /// <summary>
 /// Expects that the Actual type implements the interface provided
 /// as a generic parameter
 /// </summary>
 /// <param name="to">Continuation to operate on</param>
 /// <param name="expected">Interface type which should be implemented</param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <returns></returns>
 public static IMore <Type> Implement(
     this ITo <Type> to,
     Type expected,
     string customMessage
     )
 {
     return(to.Implement(expected, () => customMessage));
 }
Esempio n. 18
0
 /// <summary>
 /// Tests whether the Actual string is matched by the given Regex
 /// </summary>
 /// <param name="matched">Continuation to operate on</param>
 /// <param name="regex">Regex string to match with</param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <returns>More continuation for Actual string</returns>
 public static IStringMore Match(
     this ITo <string> matched,
     string regex,
     string customMessage
     )
 {
     return(matched.Match(regex, () => customMessage));
 }
 /// <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="customMessage">Custom message to add into failure messages</param>
 /// <typeparam name="T">Type of object being tested</typeparam>
 public static IMore <T> Equal <T>(
     this ITo <T> continuation,
     T?expected,
     string customMessage
     ) where T : struct
 {
     return(continuation.Equal(expected, () => customMessage));
 }
 /// <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));
 }
 /// <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="customMessage">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,
     string customMessage
     )
 {
     continuation.Match(test, () => customMessage);
 }
Esempio n. 22
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="customMessage">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,
     string customMessage
     ) where T : struct
 {
     continuation.Equal(expected, () => customMessage);
 }
Esempio n. 23
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());
 }
Esempio n. 24
0
 /// <summary>
 /// Tests whether the Actual string is matched by the given Regex
 /// </summary>
 /// <param name="matched">Continuation to operate on</param>
 /// <param name="regex">Regex string to match with</param>
 /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
 /// <returns>More continuation for Actual string</returns>
 public static IStringMore Match(
     this ITo <string> matched,
     string regex,
     Func <string> customMessageGenerator
     )
 {
     AddRegexMatcher(matched, regex, customMessageGenerator);
     return(matched.More());
 }
Esempio n. 25
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)
         );
 }
 /// <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)
                ));
 }
Esempio n. 27
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 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());
 }
 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());
 }
Esempio n. 30
0
 /// <summary>
 /// Expects a file or folder to exist at the provided path
 /// </summary>
 /// <param name="to"></param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <returns></returns>
 public static IStringMore Exist(
     this ITo <string> to,
     string customMessage)
 {
     return(to.Exist(() => customMessage));
 }