Example #1
0
 /// <summary>
 /// Tests if the actual value is approximately equal, using the
 /// provided comparer
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="comparer"></param>
 /// <param name="customMessage"></param>
 /// <returns></returns>
 public static IMore <decimal> Equal(this IApproximately <decimal> approx,
                                     decimal expected,
                                     IEqualityComparer <decimal> comparer,
                                     string customMessage)
 {
     return(approx.Equal(expected, comparer, () => customMessage));
 }
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within 1 second
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="customMessage">Custom message to include when
 /// this expectation fails</param>
 /// <returns></returns>
 public static IMore <DateTime> Equal(
     this IApproximately <DateTime> continuation,
     DateTime expected,
     string customMessage)
 {
     return(continuation.Equal(expected, () => customMessage));
 }
        /// <summary>
        /// Tests if the actual DateTime is approximately equal to the
        /// expected value within the provided allowed drift value
        /// </summary>
        /// <param name="continuation">Continuation to operate on</param>
        /// <param name="expected">Expected value</param>
        /// <param name="comparer"></param>
        /// <param name="customMessageGenerator">Generates a custom message to include when
        /// this expectation fails</param>
        /// <returns></returns>
        public static IMore <DateTime> Equal(
            this IApproximately <DateTime> continuation,
            DateTime expected,
            IEqualityComparer <DateTime> comparer,
            Func <string> customMessageGenerator)
        {
            continuation.AddMatcher(actual =>
            {
                var passed = comparer.Equals(actual, expected);

                return(new MatcherResult(passed,
                                         () =>
                {
                    var allowed =
                        comparer.TryGetPropertyValue <TimeSpan?>(
                            nameof(EqualWithinTimespan.AllowedDrift));
                    var message =
                        $@"Expected {
                                    actual.Stringify()
                                } to approximately equal {
                                    expected.Stringify()
                                }";
                    if (allowed.HasValue)
                    {
                        message += $" within a timespan of {allowed}";
                    }

                    return FinalMessageFor(() => message,
                                           customMessageGenerator);
                }));
            });
            return(continuation.More());
        }
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within the allowed drift timespan
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="allowedDrift">How much the actual value may drift from the expected
 /// value</param>
 /// <returns></returns>
 public static IMore <DateTime> Equal(
     this IApproximately <DateTime> continuation,
     DateTime expected,
     TimeSpan allowedDrift)
 {
     return(continuation.Equal(expected, allowedDrift, NULL_STRING));
 }
Example #5
0
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within the provided allowed drift value
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="allowedDrift">How much the actual value may drift from the expected
 /// value</param>
 /// <param name="customMessageGenerator">Generates a custom message to include when
 /// this expectation fails</param>
 /// <returns></returns>
 public static IMore <DateTime?> Equal(
     this IApproximately <DateTime?> continuation,
     DateTime expected,
     TimeSpan allowedDrift,
     Func <string> customMessageGenerator)
 {
     continuation.AddMatcher(actual =>
     {
         var delta = actual == null
                         ? allowedDrift.TotalMilliseconds + 1
                         : Math.Abs((actual.Value - expected)
                                    .TotalMilliseconds);
         var allowed = Math.Abs(allowedDrift.TotalMilliseconds);
         var passed  = delta <= allowed;
         return(new MatcherResult(passed,
                                  () => MessageHelpers.FinalMessageFor(()
                                                                       => $@"Expected {
                             actual.Stringify()
                         } to approximately equal {
                             expected.Stringify()
                         } within a timespan of {
                             allowedDrift.Stringify()
                         }",
                                                                       customMessageGenerator)));
     });
     return(continuation.More());
 }
Example #6
0
 /// <summary>
 /// Tests if the actual value is approximately equal, to two decimal
 /// places
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="customMessageGenerator"></param>
 /// <returns></returns>
 public static IMore <decimal> Equal(this IApproximately <decimal> approx,
                                     decimal expected,
                                     Func <string> customMessageGenerator)
 {
     return(approx.Equal(expected,
                         new DecimalsEqualToDecimalPlacesRounded(2),
                         customMessageGenerator));
 }
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within 1 second
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="customMessageGenerator">Generates a custom message to include when
 /// this expectation fails</param>
 /// <returns></returns>
 public static IMore <DateTime> Equal(
     this IApproximately <DateTime> continuation,
     DateTime expected,
     Func <string> customMessageGenerator)
 {
     return(continuation.Equal(expected,
                               TimeSpan.FromSeconds(1),
                               customMessageGenerator));
 }
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within the provided allowed drift value
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="allowedDrift">How much the actual value may drift from the expected
 /// value</param>
 /// <param name="customMessageGenerator">Generates a custom message to include when
 /// this expectation fails</param>
 /// <returns></returns>
 public static IMore <DateTime> Equal(
     this IApproximately <DateTime> continuation,
     DateTime expected,
     TimeSpan allowedDrift,
     Func <string> customMessageGenerator)
 {
     return(continuation.Equal(expected,
                               new EqualWithinTimespan(allowedDrift),
                               customMessageGenerator));
 }
Example #9
0
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within the provided allowed drift value
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <param name="allowedDrift">How much the actual value may drift from the expected
 /// value</param>
 /// <param name="customMessage">Custom message to include when
 /// this expectation fails</param>
 /// <returns></returns>
 public static IMore <DateTime?> Equal(
     this IApproximately <DateTime?> continuation,
     DateTime expected,
     TimeSpan allowedDrift,
     string customMessage)
 {
     return(continuation.Equal(expected,
                               allowedDrift,
                               () => customMessage));
 }
Example #10
0
 /// <summary>
 /// Tests if the actual value is approximately equal, using the
 /// provided comparer
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="comparer"></param>
 /// <param name="customMessageGenerator"></param>
 /// <returns></returns>
 public static IMore <decimal> Equal(this IApproximately <decimal> approx,
                                     decimal expected,
                                     IEqualityComparer <decimal> comparer,
                                     Func <string> customMessageGenerator)
 {
     approx.AddMatcher(actual =>
     {
         var passed = comparer.Equals(actual, expected);
         return(new MatcherResult(passed,
                                  () => FinalMessageFor(
                                      () => $@"Expected {
                         actual.Stringify()
                     } to approxmiately equal {
                         expected.Stringify()
                     }",
                                      customMessageGenerator)));
     });
     return(approx.More());
 }
Example #11
0
 /// <summary>
 /// Tests if the actual value is approximately equal, using the
 /// provided comparer
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="comparer"></param>
 /// <returns></returns>
 public static IMore <decimal> Equal(this IApproximately <decimal> approx,
                                     decimal expected,
                                     IEqualityComparer <decimal> comparer)
 {
     return(approx.Equal(expected, comparer, NULL_STRING));
 }
Example #12
0
 /// <summary>
 /// Tests if the actual value is approximately equal, to two decimal
 /// places
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <returns></returns>
 public static IMore <decimal> Equal(this IApproximately <decimal> approx,
                                     decimal expected)
 {
     return(approx.Equal(expected, MessageHelpers.NULL_STRING));
 }
 /// <summary>
 /// Tests if the actual value is approximately equal, using the
 /// provided comparer
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="comparer"></param>
 /// <returns></returns>
 public static IMore <double> Equal(this IApproximately <double> approx,
                                    double expected,
                                    IEqualityComparer <double> comparer)
 {
     return(approx.Equal(expected, comparer, MessageHelpers.NULL_STRING));
 }
 /// <summary>
 /// Tests if the actual value is approximately equal, to two double
 /// places
 /// </summary>
 /// <param name="approx"></param>
 /// <param name="expected"></param>
 /// <param name="customMessage"></param>
 /// <returns></returns>
 public static IMore <double> Equal(this IApproximately <double> approx,
                                    double expected,
                                    string customMessage)
 {
     return(approx.Equal(expected, () => customMessage));
 }
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within 1 second
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <returns></returns>
 public static IMore <DateTime> Equal(
     this IApproximately <DateTime> continuation,
     DateTime expected)
 {
     return(continuation.Equal(expected, NULL_STRING));
 }
Example #16
0
 /// <summary>
 /// Tests if the actual DateTime is approximately equal to the
 /// expected value within 1 second
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected value</param>
 /// <returns></returns>
 public static IMore <DateTime?> Equal(
     this IApproximately <DateTime?> continuation,
     DateTime expected)
 {
     return(continuation.Equal(expected, MessageHelpers.NULL_STRING));
 }