Exemple #1
0
        private static IVerificationTarget <bool?> ExpectBooleanValue(
            IVerificationTarget <bool?> target,
            bool?expectedValue,
            FormattableString?message)
        {
            return(CallbackAssertion.Create(
                       target,
                       context =>
            {
                if (target.Value == expectedValue)
                {
                    return true;
                }

                var writer = context.Writer;

                context.WriteMessage(message);

                using (writer.Indent())
                {
                    writer.WriteLine($"Expected: {expectedValue}");
                    writer.WriteLine($"But was:  {target}");
                }

                return false;
            }));
        }
        /// <summary>
        ///   Verifies that the given value is not null.
        /// </summary>
        public static IVerificationTarget <T?> NotNull <T>(
            this IVerificationTarget <T?> target,
            FormattableString?message = null)
            where T : struct
        {
            return(CallbackAssertion.Create(
                       target,
                       context =>
            {
                if (!target.Value.HasValue)
                {
                    return true;
                }

                context.WriteMessage(message);

                using (context.Writer.Indent())
                {
                    context.Writer.WriteLine($"Expected: not <null>");
                    context.Writer.WriteLine($"But was:  <null>");
                }

                return false;
            }));
        }
Exemple #3
0
            /// <inheritdoc />
            public override bool Apply(IVerificationTarget <T> value, Context context)
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                return(_callback.Invoke(context));
            }
Exemple #4
0
        public static IVerificationTarget <T> Create <T>(IVerificationTarget <T> target,
                                                         ValidateAndWriteErrorCallback callback)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            target.AddAssertion(new CallbackBasedAssertion <T>(callback));
            return(target);
        }
Exemple #5
0
 /// <summary>
 ///   Verifies that the given value is equal to false.
 /// </summary>
 public static IVerificationTarget <bool?> False(
     this IVerificationTarget <bool?> target,
     FormattableString?message = null)
 => ExpectBooleanValue(target, false, message);
 public abstract bool Apply(IVerificationTarget <T> value, Context context);
Exemple #7
0
 /// <summary>
 ///   Verifies that the given value is equal to the given value.
 /// </summary>
 public static IVerificationTarget <T> EqualTo <T>(
     this IVerificationTarget <T> target,
     T comparisonValue,
     FormattableString?message = null)
 => EqualTo(target, comparisonValue, null !, message);
 /// <summary>
 ///   Verifies that the given value is greater than the comparison value.
 /// </summary>
 public static IVerificationTarget <T?> GreaterThan <T>(
     this IVerificationTarget <T?> value,
     T comparisonValue,
     FormattableString?message = null)
     where T : struct, IComparable <T>
 => GreaterThan(value, comparisonValue, null !, message);