Esempio n. 1
0
 /// <summary>
 /// Creates expectation for values to be null.
 /// </summary>
 /// <param name="builder"></param>
 public static Expectation <T> BeNull <T>(this IExpectationComposer builder) where T : class
 {
     return(builder.ComposeSimple <T>(formatter => "null", x => x == null));
 }
Esempio n. 2
0
        private static Expectation <string> Match(IExpectationComposer composer, string pattern, RegexOptions options, string format)
        {
            var regex = new Regex($"^{pattern}$", options);

            return(composer.ComposeSimple(formatter => format, (string value) => value != null && regex.IsMatch(value)));
        }
Esempio n. 3
0
 /// <summary>
 /// Creates expectation for values to be null.
 /// </summary>
 /// <param name="builder"></param>
 public static Expectation <object> BeNull(this IExpectationComposer builder)
 {
     return(builder.ComposeSimple <object>(formatter => "null", x => x == null));
 }
Esempio n. 4
0
 /// <summary>
 /// Creates expectation for strings to match regex pattern specified by <paramref name="pattern"/> parameter.
 /// </summary>
 /// <param name="composer">Composer</param>
 /// <param name="pattern">Expected pattern</param>
 public static Expectation <string> Match(this IExpectationComposer composer, string pattern)
 {
     return(Match(composer, pattern, RegexOptions.None, $"matches '{pattern}'"));
 }
Esempio n. 5
0
 /// <summary>
 /// Creates expectation for strings to match regex pattern specified by <paramref name="pattern"/> parameter, where character case is ignored.
 /// </summary>
 /// <param name="composer">Composer</param>
 /// <param name="pattern">Expected pattern</param>
 public static Expectation <string> MatchIgnoreCase(this IExpectationComposer composer, string pattern)
 {
     return(Match(composer, pattern, RegexOptions.IgnoreCase, $"matches '{pattern}' ignore case"));
 }
Esempio n. 6
0
 /// <summary>
 /// Creates expectation for strings to match pattern specified by <paramref name="pattern"/> parameter.
 ///
 /// The <paramref name="pattern"/> may have special characters:
 /// <list type="bullet">
 /// <item><description>* - 0-more characters</description></item>
 /// <item><description>? - 1 character</description></item>
 /// <item><description># - 1 digit</description></item>
 /// </list>
 /// </summary>
 /// <param name="composer">Composer</param>
 /// <param name="pattern">Expected pattern</param>
 public static Expectation <string> BeLike(this IExpectationComposer composer, string pattern)
 {
     return(BeLike(composer, pattern, RegexOptions.None, $"like '{pattern}'"));
 }
Esempio n. 7
0
 /// <summary>
 /// Creates expectation for strings to match pattern specified by <paramref name="pattern"/> parameter, where character case is ignored.
 ///
 /// The <paramref name="pattern"/> may have special characters:
 /// <list type="bullet">
 /// <item><description>* - 0-more characters</description></item>
 /// <item><description>? - 1 character</description></item>
 /// <item><description># - 1 digit</description></item>
 /// </list>
 /// </summary>
 /// <param name="composer">Composer</param>
 /// <param name="pattern">Expected pattern</param>
 public static Expectation <string> BeLikeIgnoreCase(this IExpectationComposer composer, string pattern)
 {
     return(BeLike(composer, pattern, RegexOptions.IgnoreCase, $"like '{pattern}' ignore case"));
 }
Esempio n. 8
0
 /// <summary>
 /// Creates expectation for collections to contain value specified by <paramref name="value"/> parameter.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="value">Expected value</param>
 public static Expectation <IEnumerable <T> > Contain <T>(this IExpectationComposer composer, T value)
 {
     return(composer.ComposeSimple <IEnumerable <T> >(
                formatter => $"contains '{formatter.FormatValue(value)}'",
                x => x != null && x.Contains(value)));
 }
Esempio n. 9
0
 /// <summary>
 /// Creates expectation for collections with every item fulfilling expectation specified by <paramref name="expectationBuilder"/> parameter.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="expectationBuilder">Expectation builder</param>
 public static Expectation <IEnumerable <T> > EveryItem <T>(this IExpectationComposer composer, Func <IExpectationComposer, IExpectation <T> > expectationBuilder)
 {
     return(composer.Compose(new EveryItemExpectation <T>(expectationBuilder.Invoke(Expect.To))));
 }
Esempio n. 10
0
 /// <summary>
 /// Creates expectation for values to be equal one of values in <paramref name="expectedCollection"/>.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="expectedCollection">Collection of expected values</param>
 public static Expectation <T> BeIn <T>(this IExpectationComposer composer, params T[] expectedCollection)
 {
     return(composer.ComposeSimple <T>(
                formatter => $"in '{formatter.FormatValue(expectedCollection)}'",
                expectedCollection.Contains));
 }
Esempio n. 11
0
 /// <summary>
 /// Creates expectation for values to fulfill any expectation specified by <paramref name="expectationBuilder"/> parameter.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="expectationBuilder">Expectation builder</param>
 public static Expectation <T> BeAnyTrue <T>(this IExpectationComposer composer, params Func <IExpectationComposer, IExpectation <T> >[] expectationBuilder)
 {
     return(composer.Compose(new OrExpectation <T>("any true ", expectationBuilder.Select(x => x.Invoke(Expect.To)).ToArray())));
 }
Esempio n. 12
0
 /// <summary>
 /// Creates expectation for values to be equal to <paramref name="expected"/> value.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="expected">Expected value</param>
 public static Expectation <T> Equal <T>(this IExpectationComposer composer, T expected)
 {
     return(composer.ComposeSimple <T>(
                formatter => $"equals '{formatter.FormatValue(expected)}'",
                x => Equals(x, expected)));
 }
Esempio n. 13
0
 /// <summary>
 /// Creates expectation for collections to be empty.
 /// </summary>
 /// <param name="builder"></param>
 public static Expectation <T> BeEmpty <T>(this IExpectationComposer builder) where T : IEnumerable
 {
     return(builder.ComposeSimple <T>(formatter => "empty", x => x != null && !x.Cast <object>().Any()));
 }
Esempio n. 14
0
 /// <summary>
 /// Helper method creating simple expectation based on <paramref name="predicateFn"/> and <paramref name="descriptionFn"/>.
 /// </summary>
 /// <typeparam name="T">Expectation value type</typeparam>
 /// <param name="composer">Composer</param>
 /// <param name="descriptionFn">Expectation description</param>
 /// <param name="predicateFn">Expectation predicate</param>
 public static Expectation <T> ComposeSimple <T>(this IExpectationComposer composer, Func <IValueFormattingService, string> descriptionFn, Func <T, bool> predicateFn)
 {
     return(composer.Compose(new SimpleExpectation <T>(descriptionFn, predicateFn)));
 }