Esempio n. 1
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. 2
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());
 }
 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());
 }