Ejemplo n.º 1
0
        When_asserting_different_DateTimeOffsets_representing_the_same_world_time_it_should_succeded()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var specificDate = new DateTime(2008, 5, 1, 06, 32, 00);

            var dateWithFiveHourOffset =
                new DateTimeOffset(specificDate.Add(-5.Hours()),
                                   -5.Hours());
            var dateWithSixHourOffset =
                new DateTimeOffset(specificDate.Add(-6.Hours()),
                                   -6.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            dateWithFiveHourOffset.Should().Be(dateWithSixHourOffset);
        }
        public override async Task Immediately_scheduled_commands_triggered_by_a_scheduled_command_have_their_due_time_set_to_the_causative_command_clock()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var target        = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            var clockRepository    = Configuration.Current.SchedulerClockRepository();
            var schedulerClockTime = DateTimeOffset.Parse("2016-02-13 01:00:00 AM");

            clockRepository.CreateClock(clockName, schedulerClockTime);
            Configuration.Current.UseCommandHandler <CommandTarget, TestCommand>(async(_, __) =>
            {
                if (__.ETag == "first")
                {
                    await Configuration.Current.CommandScheduler <CommandTarget>().Schedule(target.Id, new TestCommand
                    {
                        CanBeDeliveredDuringScheduling = true
                    });
                }
                else
                {
                    deliveredTime = Clock.Now();
                }
            });

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand
            {
                CanBeDeliveredDuringScheduling = true,
                ETag = "first"
            },
                                     dueTime : DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));

            await Configuration.Current
            .SchedulerClockTrigger()
            .AdvanceClock(clockName, by: 1.Hours());

            // assert
            deliveredTime.Should().Be(DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));
        }
        public void Should_Pad_To_15_Minutes_30()
        {
            DateTimeOffset result = PlayoutModeSchedulerBase <ProgramScheduleItem>
                                    .CalculateEndTimeWithFiller(
                new Dictionary <CollectionKey, IMediaCollectionEnumerator>(),
                new ProgramScheduleItemOne
            {
                MidRollFiller = new FillerPreset
                {
                    FillerKind         = FillerKind.MidRoll,
                    FillerMode         = FillerMode.Pad,
                    PadToNearestMinute = 15
                }
            },
                new DateTimeOffset(2020, 2, 1, 12, 16, 0, TimeSpan.FromHours(-5)),
                new TimeSpan(0, 12, 30),
                new List <MediaChapter>());

            result.Should().Be(new DateTimeOffset(2020, 2, 1, 12, 30, 0, TimeSpan.FromHours(-5)));
        }
Ejemplo n.º 4
0
        public async void GetSetLockoutEndDate()
        {
            // Create a user and enable lockout
            var user = new User(Guid.NewGuid())
            {
                UserName = "******"
            };
            await UserManager.CreateAsync(user);

            await UserManager.SetLockoutEnabledAsync(user.Id, true);

            // Should be able to set lockout end date
            DateTimeOffset lockoutDate = DateTimeOffset.UtcNow;
            IdentityResult result      = await UserManager.SetLockoutEndDateAsync(user.Id, lockoutDate);

            result.ShouldBeSuccess();

            // Should be able to retrieve that lockout date
            DateTimeOffset lookupDate = await UserManager.GetLockoutEndDateAsync(user.Id);

            lookupDate.Should().BeCloseTo(lockoutDate);     // Use CloseTo because C* is not accurate down to the ticks level
        }
Ejemplo n.º 5
0
        public void GameState_MaintDateReturned_CallbackInvoked()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Continue,
                NextScheduledMaintenanceUtc = "2018-11-12T04:11:14Z"
            });


            DateTimeOffset   maintDate = DateTime.MinValue;
            ManualResetEvent evt       = new ManualResetEvent(false);

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object)
            {
                MaintenanceCallback = dt =>
                {
                    maintDate = dt;
                    evt.Set();
                }
            };


            sdk.Start(false);

            evt.WaitOne();
            maintDate.Should().Be(
                DateTime.Parse(
                    "2018-11-12T04:11:14Z",
                    null,
                    DateTimeStyles.RoundtripKind));
        }
Ejemplo n.º 6
0
        public override async Task Immediately_scheduled_commands_triggered_by_a_scheduled_command_have_their_due_time_set_to_the_causative_command_clock()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var target        = new NonEventSourcedCommandTarget(Any.CamelCaseName());

            await Save(target);

            Configuration.Current.UseCommandHandler <NonEventSourcedCommandTarget, TestCommand>(async(_, cmd) =>
            {
                if (cmd.ETag == "first")
                {
                    await Schedule(target.Id,
                                   new TestCommand
                    {
                        CanBeDeliveredDuringScheduling = true
                    });
                }
                else
                {
                    deliveredTime = Clock.Now();
                }
            });

            // act
            await Schedule(target.Id,
                           new TestCommand
            {
                CanBeDeliveredDuringScheduling = true,
                ETag = "first"
            },
                           dueTime : DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));

            await AdvanceClock(clockName : clockName, by : 1.Hours());

            // assert
            deliveredTime.Should().Be(DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));
        }
        public void Should_Compare_Time_As_Local_Time()
        {
            var enumerator = new Mock <IScheduleItemsEnumerator>();

            var state = new PlayoutBuilderState(
                enumerator.Object,
                None,
                None,
                false,
                false,
                0,
                DateTime.Today.AddHours(6).ToUniversalTime());

            var scheduleItem = new ProgramScheduleItemOne
            {
                StartTime = TimeSpan.FromHours(6)
            };

            DateTimeOffset result =
                PlayoutModeSchedulerBase <ProgramScheduleItem> .GetStartTimeAfter(state, scheduleItem);

            result.Should().Be(DateTime.Today.AddHours(6));
        }
Ejemplo n.º 8
0
        public override async Task Scheduled_commands_with_no_due_time_are_delivered_at_Clock_Now_when_delivery_is_deferred()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();

            Configuration
            .Current
            .UseCommandHandler <Order, CreateOrder>(async(_, __) => deliveredTime = Clock.Now());

            // act
            await Schedule(
                new CreateOrder(Any.FullName())
            {
                CanBeDeliveredDuringScheduling = false
            },
                dueTime : null);

            await AdvanceClock(clockName : clockName, by : 1.Hours());

            // assert
            deliveredTime
            .Should()
            .Be(Clock.Now());
        }
        public override async Task Scheduled_commands_with_no_due_time_set_the_correct_clock_time_when_delivery_is_deferred()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);
            var clockRepository = Configuration.Current.SchedulerClockRepository();
            var schedulerClockTime = DateTimeOffset.Parse("2016-02-13 01:00:00 AM");
            clockRepository.CreateClock(clockName, schedulerClockTime);
            Configuration.Current.UseCommandHandler<CommandTarget,TestCommand>(async (_,__) => deliveredTime = Clock.Now());

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand
                                     {
                                         CanBeDeliveredDuringScheduling = false
                                     },
                                     dueTime: null);

            await Configuration.Current
                               .SchedulerClockTrigger()
                               .AdvanceClock(clockName, by: 1.Hours());

            // assert 
            deliveredTime.Should().Be(DateTimeOffset.Parse("2016-02-13 01:00:00 AM"));
        }
        public void Should_fail_when_asserting_datetime_value_is_equal_to_the_different_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var dateTime = new DateTimeOffset(10.March(2012), 1.Hours());
            var otherDateTime = new DateTimeOffset(11.March(2012), 1.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // 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 +1h>*failure message, but found <2012-03-10 +1h>.");
        }
            When_asserting_different_date_time_offsets_representing_the_same_world_time_it_should_succeded()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var specificDate = 1.May(2008).At(6, 32);
             
            var dateWithFiveHourOffset = new DateTimeOffset(specificDate.Add(-5.Hours()), -5.Hours());

            var dateWithSixHourOffset = new DateTimeOffset(specificDate.Add(-6.Hours()), -6.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            dateWithFiveHourOffset.Should().Be(dateWithSixHourOffset);
        }
        public override async Task Scheduled_commands_with_no_due_time_are_delivered_at_Clock_Now_when_delivery_is_deferred()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();

            Configuration
                .Current
                .UseCommandHandler<Order, CreateOrder>(async (_, __) => deliveredTime = Clock.Now());

            // act
            await Schedule(Any.Guid(),
                new CreateOrder(Any.FullName())
                {
                    CanBeDeliveredDuringScheduling = false
                },
                dueTime: null);

            await AdvanceClock(clockName: clockName, by: 1.Hours());

            // assert 
            deliveredTime
                .Should()
                .Be(Clock.Now());
        }
        public void When_asserting_subject_datetimeoffset_should_not_be_same_as_another_with_same_date_but_different_time_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31, 4, 5, 6), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2009, 12, 31, 11, 15, 11), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time that does not have date <2009-12-31>, but found it does.");
        }
        public void When_asserting_subject_datetimeoffset_is_not_close_to_an_earlier_datetimeoffset_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset time = new DateTimeOffset(2016, 06, 04, 12, 15, 31, 020, TimeSpan.Zero);
            DateTimeOffset nearbyTime = new DateTimeOffset(2016, 06, 04, 12, 15, 31, 0, TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected date and time to not be within 20 ms from <2016-06-04 12:15:31>, but found <2016-06-04 12:15:31.020>.");
        }
        public void When_asserting_subject_datetimeoffset_is_close_to_an_earlier_datetimeoffset_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset time = new DateTimeOffset(2016, 06, 04, 12, 15, 31, 020, TimeSpan.Zero);
            DateTimeOffset nearbyTime = new DateTimeOffset(2016, 06, 04, 12, 15, 31, 0, TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_a_value_is_one_of_the_specified_values_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset value = new DateTimeOffset(2016, 12, 30, 23, 58, 57, TimeSpan.FromHours(4));

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => value.Should().BeOneOf(new DateTimeOffset(2216, 1, 30, 0, 5, 7, TimeSpan.FromHours(2)), new DateTimeOffset(2016, 12, 30, 23, 58, 57, TimeSpan.FromHours(4)));

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
        public void When_a_value_is_not_one_of_the_specified_values_it_should_throw_with_descriptive_message()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset value = new DateTimeOffset(31.December(2016), 1.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => value.Should().BeOneOf(new[] { value.AddDays(1), value.AddMonths(1) }, "because it's true");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected value to be one of {<2017-01-01 +1h>, <2017-01-31 +1h>} because it's true, but found <2016-12-31 +1h>.");
        }
        public void When_a_value_is_not_one_of_the_specified_values_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var value = new DateTimeOffset(31.December(2016), 1.Hours());
            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => value.Should().BeOneOf(value.AddDays(1), value.AddHours(4));

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected value to be one of {<2017-01-01 +1h>, <2016-12-31 04:00:00 +1h>}, but found <2016-12-31 +1h>.");
        }
        public void When_asserting_subject_datetimeoffset_should_not_have_same_date_as_another_but_it_doesnt_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2009, 12, 30), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_subject_datetimeoffset_should_have_same_date_as_another_but_it_doesnt_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2009, 12, 30), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected a date and time with date <2009-12-30>, but found <2009-12-31>.");
        }
        public void When_asserting_a_DateTime_against_a_DateTimeOffset_it_should_validate_against_world_time()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var todayDateTimeOffset = new DateTimeOffset(Today);

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            todayDateTimeOffset.Should().Be(Today);
        }
Ejemplo n.º 22
0
        public async Task ReschedulesOnError(int configMaxAttemptCount)
        {
            schedulerConfiguration.HandleAttemptCount = configMaxAttemptCount;

            FakeClock.Setup();
            FakeClock.Now = new DateTimeOffset(2019, 1, 1, 0, 0, 0, TimeSpan.Zero);

            var job = new Job1();

            Action <IJob, Exception> errorHandler = null;

            workerProcess.When(x => x.EnqueueJob(job, Arg.Any <Action <IJob, Exception> >()))
            .Do(ci =>
            {
                errorHandler = ci.ArgAt <Action <IJob, Exception> >(1);
            });

            DateTimeOffset scheduleTime = DateTimeOffset.MinValue;

            schedulerProcess.When(x => x.ScheduleJob(job, Arg.Any <DateTimeOffset>(), Arg.Any <Action <IJob, Exception> >()))
            .Do(ci =>
            {
                scheduleTime = ci.ArgAt <DateTimeOffset>(1);
                errorHandler = ci.ArgAt <Action <IJob, Exception> >(2);
            });

            await sut.EnqeueJobAsync(job, null);

            int Pow(int bas, int exp)
            {
                return(Enumerable
                       .Repeat(bas, exp)
                       .Aggregate(1, (a, b) => a * b));
            }

            for (int numberAttempts = 1; numberAttempts <= configMaxAttemptCount; numberAttempts++)
            {
                errorHandler.Should().NotBeNull();

                var currentErrorHandler = errorHandler;
                errorHandler = null;

                var exception = new Exception();
                currentErrorHandler(job, exception);

                schedulerProcess.Received(Math.Min(numberAttempts, configMaxAttemptCount - 1))
                .ScheduleJob(job, Arg.Any <DateTimeOffset>(), Arg.Any <Action <IJob, Exception> >());

                if (numberAttempts != configMaxAttemptCount) // should retry
                {
                    int  delayMultiplier = Pow(schedulerConfiguration.HandleRetryTimeoutMultiplier, numberAttempts - 1);
                    long minDelay        = schedulerConfiguration.MinHandleRetryTimeoutStep.Ticks * delayMultiplier;
                    long maxDelay        = schedulerConfiguration.MaxHandleRetryTimeoutStep.Ticks * delayMultiplier;

                    scheduleTime.Should().BeOnOrAfter(FakeClock.Now + TimeSpan.FromTicks(minDelay));
                    scheduleTime.Should().BeOnOrBefore(FakeClock.Now + TimeSpan.FromTicks(maxDelay));
                }
            }

            workerProcess.Received(1).EnqueueJob(job, Arg.Any <Action <IJob, Exception> >()); // only once
        }
        public void When_asserting_a_point_of_time_is_before_a_later_point_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset earlierDate = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset laterDate = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero).AddMinutes(5);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => earlierDate.Should().BeBefore(laterDate);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_subject_datetimeoffset_should_not_have_offset_with_different_value_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31, 23, 59, 00), TimeSpan.Zero);
            TimeSpan expectation = TimeSpan.FromHours(3);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_a_point_of_time_is_not_before_another_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset earlierDate = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset laterDate = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero).AddMinutes(5);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => earlierDate.Should().NotBeBefore(laterDate);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time on or after <2016-06-04 00:05:00>, but found <2016-06-04>.");
        }
 public void Bcl_Treats_Local_And_Unspecified_As_Equal_When_Ticks_Are_Equal()
 {
     _local.Should().Be(_unspecified);
     _local.Ticks.Should().Be(_unspecified.Ticks);
     _local.UtcTicks.Should().Be(_unspecified.UtcTicks);
 }
        public void When_asserting_subject_is_not_before_earlier_expected_datetimeoffset_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset expected = new DateTimeOffset(new DateTime(2016, 06, 03), TimeSpan.Zero);
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);

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

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public override async Task Scheduled_commands_with_no_due_time_set_the_correct_clock_time_when_delivery_is_deferred()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var configuration = Configuration.Current;
            var clockTrigger = configuration.SchedulerClockTrigger();
            await clockTrigger.AdvanceClock(clockName, DateTimeOffset.Parse("2046-02-13 01:00:00 AM"));
            configuration
                .UseCommandHandler<Order, CreateOrder>(async (_, __) => deliveredTime = Clock.Now());

            // act
            await configuration.CommandScheduler<Order>()
                               .Schedule(Any.Guid(),
                                         new CreateOrder(Any.FullName())
                                         {
                                             CanBeDeliveredDuringScheduling = false
                                         },
                                         dueTime: null);

            await clockTrigger
                .AdvanceClock(clockName, by: 1.Hours());

            // assert 
            deliveredTime.Should().Be(DateTimeOffset.Parse("2046-02-13 01:00:00 AM"));
        }
        public void When_asserting_subject_datetimeoffset_is_before_the_same_datetimeoffset_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset expected = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);

            //-----------------------------------------------------------------------------------------------------------
            // 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_different_date_time_offsets_representing_different_world_times_it_should_not_succeded()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var specificDate = 1.May(2008).At(6, 32);

            var dateWithFiveHourOffset = new DateTimeOffset(specificDate);
            var dateWithSixHourOffset = new DateTimeOffset(specificDate, 1.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            dateWithFiveHourOffset.Should().NotBe(dateWithSixHourOffset);
        }
        public void When_asserting_subject_datetimeoffset_is_on_or_before_the_same_date_as_the_expected_datetimeoffset_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public override async Task Immediately_scheduled_commands_triggered_by_a_scheduled_command_have_their_due_time_set_to_the_causative_command_clock()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);
            var clockRepository = Configuration.Current.SchedulerClockRepository();
            var schedulerClockTime = DateTimeOffset.Parse("2016-02-13 01:00:00 AM");
            clockRepository.CreateClock(clockName, schedulerClockTime);
            Configuration.Current.UseCommandHandler<CommandTarget, TestCommand>(async (_, __) =>
            {
                if (__.ETag == "first")
                {
                    await Configuration.Current.CommandScheduler<CommandTarget>().Schedule(target.Id, new TestCommand
                    {
                          CanBeDeliveredDuringScheduling = true
                    });
                }
                else
                {
                    deliveredTime = Clock.Now();
                }
            });

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand
                                     {
                                         CanBeDeliveredDuringScheduling = true,
                                         ETag = "first"
                                     },
                                     dueTime: DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));

            await Configuration.Current
                               .SchedulerClockTrigger()
                               .AdvanceClock(clockName, by: 1.Hours());

            // assert 
            deliveredTime.Should().Be(DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));
        }
        public void When_asserting_subject_datetimeoffset_is_not_on_or_before_earlier_expected_datetimeoffset_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2016, 06, 03), TimeSpan.Zero);

            //-----------------------------------------------------------------------------------------------------------
            // 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 It_should_treat_Local_and_Utc_as_equivalent_even_though_the_string_representations_are_not_equal()
 {
     local.Equals(utc).Should().BeTrue();
     local.Should().Be(utc);
     local.ToRoundtripString().Should().NotBe(utc.ToRoundtripString());
 }
        public void Should_fail_when_asserting_datetimeoffset_value_is_not_equal_to_the_same_value()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var dateTime = new DateTimeOffset(10.March(2012), 1.Hours());
            var sameDateTime = new DateTimeOffset(10.March(2012), 1.Hours());

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected date and time not to be <2012-03-10 +1h> because we want to test the failure message, but it is.");
        }
        public void When_asserting_subject_datetimeoffset_should_have_offset_with_different_value_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31, 23, 59, 00), TimeSpan.Zero);
            TimeSpan expectation = TimeSpan.FromHours(3);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage("Expected offset to be 3h, but found 0.");
        }
Ejemplo n.º 37
0
 public static void Scenario2(DateTimeOffset actual)
 {
     "Then the actual is expected"
     .x(() => actual.Should().Be(expected));
 }
        public void When_asserting_different_DateTimeOffsets_representing_the_same_world_time_it_should_succeded()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var specificDate = new DateTime(2008, 5, 1, 06, 32, 00);

            var dateWithFiveHourOffset =
                new DateTimeOffset(specificDate.Add(-5.Hours()),
                    -5.Hours());
            var dateWithSixHourOffset =
                new DateTimeOffset(specificDate.Add(-6.Hours()),
                    -6.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            dateWithFiveHourOffset.Should().Be(dateWithSixHourOffset);
        }
            When_asserting_different_DateTimeOffsets_representing_different_world_times_it_should_not_succeded()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var specificDate = new DateTime(2008, 5, 1, 06, 32, 00);

            var dateWithFiveHourOffset = new DateTimeOffset(specificDate);
            var dateWithSixHourOffset = new DateTimeOffset(specificDate, 1.Hours());

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            dateWithFiveHourOffset.Should().NotBe(dateWithSixHourOffset);
        }
        public void When_asserting_subject_datetimeoffset_is_after_later_expected_datetimeoffset_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2016, 06, 05), TimeSpan.Zero);

            //-----------------------------------------------------------------------------------------------------------
            // 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 When_asserting_subject_datetimeoffset_should_be_same_as_another_with_same_date_but_different_time_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2009, 12, 31, 4, 5, 6), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2009, 12, 31, 11, 15, 11), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_subject_datetimeoffset_is_not_after_later_expected_datetimeoffset_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            DateTimeOffset subject = new DateTimeOffset(new DateTime(2016, 06, 04), TimeSpan.Zero);
            DateTimeOffset expectation = new DateTimeOffset(new DateTime(2016, 06, 05), TimeSpan.Zero);

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

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
Ejemplo n.º 43
0
 public void ElTiempoPasa()
 {
     _fechaYHora.Should().BeOnOrBefore(_ahora);
     _ahora.Should().BeOnOrAfter(_fechaYHora.DateTime);
 }