public void DateTimeExtensionsTests_ToSaml2DateStripsSecondFractions()
        {
            var subject = new DateTime(2014, 07, 14, 16, 23, 47, 153, DateTimeKind.Utc)
            .ToSaml2DateTimeString();

            subject.Should().Be("2014-07-14T16:23:47Z");
        }
        public void DateTimeExtensionsTestToSaml2Date()
        {
            var subject = new DateTime(2014, 03, 02, 22, 42, 54, DateTimeKind.Utc)
            .ToLocalTime().ToSaml2DateTimeString();

            subject.Should().Be("2014-03-02T22:42:54Z");
        }
Пример #3
0
 public void VerifyBothNowValuesMatch()
 {
     var custom = TimeObservations.PrimaryDateTime;
     var customValue = new DateTime(custom.Year, custom.Month, custom.Day, custom.Hour, custom.Minute, custom.Second);
     var system = TimeObservations.SecondaryDateTime;
     var systemValue = new DateTime(system.Year, system.Month, system.Day, system.Hour, system.Minute, system.Second);
     customValue.Should().Be(systemValue);
 }
Пример #4
0
        public void Should_Handle_Negative_Numbers()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().On(-1);

            var input = new DateTime(2000, 1, 1, 1, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 2, 28);
            expectedTime.Should().Equal(scheduledTime.Date);
        }
Пример #5
0
        public void TestConvertOpaToLocalDateTime()
        {
            const string opaDateTime = "2018-08-01 00:00:00";

            System.DateTime target = new System.DateTime(2018, 8, 1);

            IDateTimeProvider dateTimeProvider = new DateTimeProvider();

            System.DateTime dateTest = dateTimeProvider.ConvertOpaToLocalDateTime(opaDateTime);

            dateTest.Should().Be(target);
        }
            public void When_DefaultDateTimeProvider_Then_ReturnCurrentTime(int toleranceMs)
            {
                // Arrange

                System.DateTime   systemNow = System.DateTime.UtcNow;
                IDateTimeProvider dtp       = new DefaultDateTimeProvider();

                // Act
                System.DateTime dtpNow = dtp.UtcNow;

                // Assert
                dtpNow.Should().BeCloseTo(systemNow, toleranceMs);
            }
Пример #7
0
        public void TestConvertUtcToUk()
        {
            System.DateTime utcNow = System.DateTime.UtcNow;

            IDateTimeProvider dateTimeProvider = new DateTimeProvider();

            System.DateTime dateTest = dateTimeProvider.ConvertUtcToUk(utcNow);

            // https://stackoverflow.com/questions/4034923/how-to-represent-the-current-uk-time
            TimeZoneInfo britishZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");

            System.DateTime dateBaseline = TimeZoneInfo.ConvertTime(utcNow, TimeZoneInfo.Utc, britishZone);

            dateTest.Should().Be(dateBaseline);
        }
Пример #8
0
        public void Should_Override_Existing_Minutes_And_Seconds_If_At_Method_Is_Called()
        {
            var task = new Mock<ITask>();
            var schedule = new Schedule(task.Object);
            schedule.ToRunEvery(2).Months().On(1).At(3, 15);

            var input = new DateTime(2000, 1, 1, 5, 23, 25);
            var scheduledTime = schedule.CalculateNextRun(input);
            var expectedTime = new DateTime(2000, 3, 1);
            expectedTime.Should().Equal(scheduledTime.Date);

            scheduledTime.Hour.Should().Equal(3);
            scheduledTime.Minute.Should().Equal(15);
            scheduledTime.Second.Should().Equal(0);
        }
            public void When_MockedDateTimeProvider_Then_ReturnMockTime(int toleranceMs)
            {
                // Arrange

                System.DateTime fakeSystemNow = new System.DateTime(2019, 12, 2, 09, 34, 12, 345);
                var             dateTimeMock  = new Mock <IDateTimeProvider>();

                dateTimeMock.SetupGet(tp => tp.UtcNow).Returns(fakeSystemNow);
                IDateTimeProvider dtp = dateTimeMock.Object;

                // Act
                System.DateTime dtpNow = dtp.UtcNow;

                // Assert
                dtpNow.Should().BeCloseTo(fakeSystemNow, toleranceMs);
            }
        public void When_nullable_datetimeoffset_value_with_a_value_to_have_a_value_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset? nullableDateTime = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => nullableDateTime.Should().HaveValue();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void Should_succeed_when_asserting_nullable_datetime_value_with_a_value_to_have_a_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime? nullableDateTime = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => nullableDateTime.Should().HaveValue();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void Should_fail_when_asserting_datetime_value_is_equal_to_the_different_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var dateTime = new DateTime(2012, 03, 10);
            var otherDateTime = new DateTime(2012, 03, 11);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => dateTime.Should().Be(otherDateTime, "because we want to test the failure {0}", "message");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage(
                    "Expected date and time to be <2012-03-11>*failure message, but found <2012-03-10>.", ComparisonMode.Wildcard);
        }
Пример #13
0
 public void date_to_first_day()
 {
     var rez = new DateTime(2014, 12, 28).ToFirstDay();
     rez.Should().Be(new DateTime(2014, 12, 1));
 }
Пример #14
0
        public void GetRaceFinishTime_Default_ReturnsTimeDifferenceFromStartDate()
        {
            var race = new Race();
            race.StartRace(new DateTime(2016, 9, 8, 0, 0, 0, 0));

            var finishDate = new DateTime(2016, 9, 8, 0, 2, 30, 45);
            var finishTime = race.GetRaceFinishTime(finishDate);

            finishDate.Should().HaveMinute(2).And.HaveSecond(30).And.HaveHour(0);
        }
        public void When_asserting_subject_datetime_is_after_later_expected_datetime_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime subject = new DateTime(2016, 06, 04);
            DateTime expectation = new DateTime(2016, 06, 05);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeAfter(expectation);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time after <2016-06-05>, but found <2016-06-04>.");
        }
        public void Should_succeed_when_asserting_nullable_numeric_value_equals_the_same_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset? nullableDateTimeA = new DateTime(2016, 06, 04);
            DateTimeOffset? nullableDateTimeB = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                nullableDateTimeA.Should().Be(nullableDateTimeB);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void When_two_date_times_are_equal_but_the_kinds_differ_it_should_still_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime dateTimeA = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Unspecified);
            DateTime dateTimeB = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Utc);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                dateTimeA.Should().Be(dateTimeB);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void When_asserting_subject_datetime_is_before_the_same_datetime_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime expected = new DateTime(2016, 06, 04);
            DateTime subject = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------

            Action act = () => subject.Should().BeBefore(expected);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time before <2016-06-04>, but found <2016-06-04>.");
        }
        public void When_asserting_subject_datetime_is_not_before_the_same_datetime_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime expected = new DateTime(2016, 06, 04);
            DateTime subject = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------

            Action act = () => subject.Should().NotBeBefore(expected);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_a_date_time_is_expected_to_have_a_date_part_that_is_the_same_as_a_specified_datetime_and_it_does_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new DateTime(2009, 12, 31, 4, 5, 6);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeSameDateAs(new DateTime(2009, 12, 31, 11, 15, 11));

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_subject_datetime_is_close_to_an_ealier_datetime_by_35ms_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime time = new DateTime(2016, 06, 04).At(12, 15, 31, 035);
            DateTime nearbyTime = new DateTime(2016, 06, 04).At(12, 15, 31);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => time.Should().BeCloseTo(nearbyTime, 35);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void Should_succeed_when_asserting_datetimeoffset_value_is_equal_to_the_same_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset dateTime = new DateTime(2016, 06, 04);
            DateTimeOffset sameDateTime = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => dateTime.Should().Be(sameDateTime);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void Should_fail_when_asserting_nullable_datetimeoffset_value_with_a_value_to_be_null()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset? nullableDateTime = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                nullableDateTime.Should().NotHaveValue();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>();
        }
        public void Should_fail_when_asserting_nullable_numeric_value_equals_a_different_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset? nullableDateTimeA = new DateTime(2016, 06, 04);
            DateTimeOffset? nullableDateTimeB = new DateTime(2016, 06, 04).AddDays(2);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                nullableDateTimeA.Should().Be(nullableDateTimeB);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>();
        }
        public void Should_support_chaining_constraints_with_and()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset yesterday = new DateTime(2016, 06, 04).AddDays(-1);
            DateTimeOffset? nullableDateTime = new DateTime(2016, 06, 04);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                nullableDateTime.Should()
                    .HaveValue()
                    .And
                    .BeAfter(yesterday);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void When_asserting_subject_datetime_is_not_on_or_before_earlier_expected_datetime_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime subject = new DateTime(2016, 06, 04);
            DateTime expectation = new DateTime(2016, 06, 03);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().NotBeOnOrBefore(expectation);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();

        }
        public void When_asserting_subject_datetime_is_not_on_or_before_earlier_expected_datetime_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime subject = new DateTime(2016, 06, 04);
            DateTime expectation = new DateTime(2016, 06, 03);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeOnOrBefore(expectation);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time on or before <2016-06-03>, but found <2016-06-04>.");

        }
        public void When_a_date_time_is_expected_to_have_a_specified_date_part_but_it_doesnt_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new DateTime(2009, 12, 31);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeSameDateAs(new DateTime(2009, 12, 30));

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected a date and time with date <2009-12-30>, but found <2009-12-31>.");
        }
        public void Should_fail_when_asserting_datetime_value_is_not_equal_to_the_same_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var dateTime = new DateTime(2012, 03, 10);
            var sameDateTime = new DateTime(2012, 03, 10);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act =
                () => dateTime.Should().NotBe(sameDateTime, "because we want to test the failure {0}", "message");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Did not expect date and time to be <2012-03-10> because we want to test the failure message.");
        }
        public void When_a_date_time_is_expected_to_have_a_date_part_that_is_the_same_as_a_fully_specified_date_time_but_it_doesnt_it_should_fail_with_the_correct_message()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new DateTime(2015, 1, 7, 12, 22, 13);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeSameDateAs(new DateTime(2015, 2, 7, 12, 22, 13), "because we want to test the failure {0}", "message");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                    "Expected a date and time with date <2015-02-07> because we want to test the failure message, but found <2015-01-07 12:22:13>.");
        }
        public void When_asserting_subject_datetime_is_not_close_to_an_ealier_datetime_by_35ms_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime time = new DateTime(2016, 06, 04).At(12, 15, 31, 035);
            DateTime nearbyTime = new DateTime(2016, 06, 04).At(12, 15, 31);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => time.Should().NotBeCloseTo(nearbyTime, 35);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected date and time to not be within 35 ms from <2016-06-04 12:15:31>, but found <2016-06-04 12:15:31.035>.");
        }
        public void When_asserting_subject_datetime_is_not_after_later_expected_datetime_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime subject = new DateTime(2016, 06, 04);
            DateTime expectation = new DateTime(2016, 06, 05);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().NotBeAfter(expectation);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_a_nullable_date_time_is_equal_to_a_normal_date_time_but_the_kinds_differ_it_should_still_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTime? nullableDateTime = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Unspecified);
            DateTime normalDateTime = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Utc);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                nullableDateTime.Should().Be(normalDateTime);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void Should_succeed_when_asserting_datetimeoffset_value_is_not_equal_to_a_different_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset dateTime = new DateTime(2016, 06, 04);
            DateTimeOffset otherDateTime = new DateTime(2016, 06, 05);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => dateTime.Should().NotBe(otherDateTime);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }