示例#1
0
 public static AndConstraint <DateTimeAssertions> BeNear(this DateTimeAssertions assertions,
                                                         DateTime nearbyTime,
                                                         int precision  = 850,
                                                         string because = "",
                                                         params object[] becauseArgs)
 {
     return(assertions.BeCloseTo(nearbyTime, precision, because, becauseArgs));
 }
        /// <summary>Asserts that a value is the same date as another, ignoring time.</summary>
        /// <param name="source">The source object.</param>
        /// <param name="expected">The expected value.</param>
        /// <param name="reason">The reason for the failure.</param>
        /// <param name="reasonArgs">The optional reason arguments.</param>
        /// <returns>The constraint.</returns>
        public static AndConstraint <DateTimeAssertions> BeDate(this DateTimeAssertions source, DateTime expected, string reason, params object[] reasonArgs)
        {
            var actual = source.Subject.GetValueOrDefault();

            Execute.Assertion.ForCondition(actual.Year == expected.Year && actual.Month == expected.Month && actual.Day == expected.Day)
            .BecauseOf(reason, reasonArgs)
            .FailWith("Expected {0} {reason}, but found {1}.", expected.ToString("MM/dd/yyyy"), actual.ToString("MM/dd/yyyy"));
            return(new AndConstraint <DateTimeAssertions>(source));
        }
示例#3
0
        public void Should_fail_with_descriptive_message_when_asserting_datetime_is_on_or_after_later_datetime()
        {
            DateTimeAssertions assertions = Today.Should();

            assertions.Invoking(x => x.BeOnOrAfter(Tomorrow, "because we want to test the failure {0}", "message"))
            .ShouldThrow <AssertFailedException>()
            .WithMessage(string.Format(
                             "Expected a date and time on or after <{0}> because we want to test the failure message, but found <{1}>.",
                             Tomorrow.ToString("yyyy-MM-dd"), Today.ToString("yyyy-MM-dd")));
        }
示例#4
0
        public void Should_fail_with_descriptive_message_when_asserting_datetime_is_before_earlier_datetime()
        {
            DateTimeAssertions assertions = Today.Should();

            assertions.Invoking(x => x.BeBefore(Yesterday, "because we want to test the failure {0}", "message"))
            .ShouldThrow <AssertFailedException>()
            .WithMessage(string.Format(
                             "Expected a date and time before <{0}> because we want to test the failure message, but found <{1}>.",
                             Yesterday.ToString("yyyy-MM-dd"), Today.ToString("yyyy-MM-dd")));
        }
        /// <summary>
        /// Asserts that a date time is now.
        /// </summary>
        /// <remarks>TimeContext.Current should be instance of FakeTimeContext.</remarks>
        /// <param name="dateTimeAssertions">Fluent Assertions DateTimeAssertions.</param>
        /// <param name="because">
        /// A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])" /> explaining why the assertion
        /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <see cref="!:because" />.
        /// </param>
        /// <returns>Fluent Assertions AndConstraint.</returns>
        public static AndConstraint <DateTimeAssertions> BeNow(
            this DateTimeAssertions dateTimeAssertions,
            string because = "",
            params object[] becauseArgs)
        {
            Execute.Assertion
            .ForCondition(dateTimeAssertions.Subject == TimeContext.Current.Now)
            .BecauseOf(because, becauseArgs)
            .FailWith("Expected now date time{reason}, but found {0}.", dateTimeAssertions.Subject);

            return(new AndConstraint <DateTimeAssertions>(dateTimeAssertions));
        }
示例#6
0
 /// <summary>
 /// Asserts that the <see cref="DateTime"/> instance is not the
 /// default value.
 /// </summary>
 /// <param name="because">
 /// A formatted phrase as is supported by System.String.Format(System.String,System.Object[])
 /// explaining why the assertion is needed. If the phrase does not start with the
 /// word because, it is prepended automatically.
 ///</param>
 /// <param name="becauseArgs">
 /// Zero or more objects to format using the placeholders in because.
 /// </param>
 public static AndConstraint <TAssertions> NotBeDefault <TAssertions>(this DateTimeAssertions <TAssertions> parent, string because = "", params object[] becauseArgs)
     where TAssertions : DateTimeAssertions <TAssertions>
 {
     return(parent.NotBe(default(DateTime), because, becauseArgs));
 }
示例#7
0
 public static AndConstraint <DateTimeAssertions> BeCloseToDateWithDefaultPrecision(
     this DateTimeAssertions data,
     DateTime expectedValue)
 {
     return(data.BeCloseTo(expectedValue, TestFixtureConstants.MaxDiffForComparingDateTimes));
 }
 /// <summary>Asserts that a value is the same date as another, ignoring time.</summary>
 /// <param name="source">The source object.</param>
 /// <param name="expected">The expected value.</param>
 /// <returns>The constraint.</returns>
 public static AndConstraint <DateTimeAssertions> BeDate(this DateTimeAssertions source, DateTime expected)
 {
     return(source.HaveYear(expected.Year).And.HaveMonth(expected.Month).And.HaveDay(expected.Day));
 }