Example #1
0
        public async Task When_the_clock_is_advanced_then_commands_are_delivered_in_the_expected_order()
        {
            // arrange
            VirtualClock.Start(DateTimeOffset.Parse("2016-04-08 12:00:00 PM"));

            var aggregate         = new CommandSchedulerTestAggregate(Any.Guid());
            var commandsDelivered = new List <IScheduledCommand <CommandSchedulerTestAggregate> >();
            var configuration     = Configuration.Current
                                    .TraceScheduledCommands(onDelivering: c => commandsDelivered.Add((IScheduledCommand <CommandSchedulerTestAggregate>)c));

            await configuration.Repository <CommandSchedulerTestAggregate>().Save(aggregate);

            var firstCommandSchedulesSecond = new CommandSchedulerTestAggregate.CommandThatSchedulesAnotherCommand
            {
                NextCommand = new CommandSchedulerTestAggregate.Command
                {
                    ETag = "second"
                },
                NextCommandAggregateId = aggregate.Id,
                NextCommandDueTime     = Clock.Now().AddHours(1),
                ETag = "first"
            };

            var thirdCommand = new CommandSchedulerTestAggregate.Command
            {
                ETag = "third"
            };

            var scheduler = configuration.CommandScheduler <CommandSchedulerTestAggregate>();
            await scheduler.Schedule(aggregate.Id,
                                     firstCommandSchedulesSecond,
                                     Clock.Now().AddMinutes(1));

            await scheduler.Schedule(aggregate.Id,
                                     thirdCommand,
                                     Clock.Now().AddDays(1));

            // act
            VirtualClock.Current.AdvanceBy(1.Days().And(1.Seconds()));

            // assert
            Console.WriteLine(commandsDelivered.Select(c => c.DueTime).ToLogString());

            commandsDelivered
            .Select(c => c.Command.ETag)
            .Should()
            .ContainInOrder("first", "second", "third");
        }
        public async Task When_the_clock_is_advanced_then_commands_are_delivered_in_the_expected_order()
        {
            // arrange
            VirtualClock.Start(DateTimeOffset.Parse("2016-04-08 12:00:00 PM"));

            var aggregate = new CommandSchedulerTestAggregate(Any.Guid());
            var commandsDelivered = new List<IScheduledCommand<CommandSchedulerTestAggregate>>();
            var configuration = Configuration.Current
                                             .TraceScheduledCommands(onDelivering: c => commandsDelivered.Add((IScheduledCommand<CommandSchedulerTestAggregate>) c));

            await configuration.Repository<CommandSchedulerTestAggregate>().Save(aggregate);

            var firstCommandSchedulesSecond = new CommandSchedulerTestAggregate.CommandThatSchedulesAnotherCommand
            {
                NextCommand = new CommandSchedulerTestAggregate.Command
                {
                    ETag = "second"
                },
                NextCommandAggregateId = aggregate.Id,
                NextCommandDueTime = Clock.Now().AddHours(1),
                ETag = "first"
            };

            var thirdCommand = new CommandSchedulerTestAggregate.Command
            {
                ETag = "third"
            };

            var scheduler = configuration.CommandScheduler<CommandSchedulerTestAggregate>();
            await scheduler.Schedule(aggregate.Id,
                                     firstCommandSchedulesSecond,
                                     Clock.Now().AddMinutes(1));

            await scheduler.Schedule(aggregate.Id,
                                     thirdCommand,
                                     Clock.Now().AddDays(1));

            // act
            VirtualClock.Current.AdvanceBy(1.Days().And(1.Seconds()));

            // assert
            Console.WriteLine(commandsDelivered.Select(c => c.DueTime).ToLogString());

            commandsDelivered
                .Select(c => c.Command.ETag)
                .Should()
                .ContainInOrder("first", "second", "third");
        }