Example #1
0
        private async Task ValidateScheduleHappens(Func <IJob, IJobScheduler, Task <IJobId> > schedule)
        {
            // Arrange
            var testId            = ThingyId.New;
            var pingId            = PingId.New;
            var executeCommandJob = PublishCommandJob.Create(new ThingyPingCommand(testId, pingId), Resolver);

            // Act
            var jobId = await schedule(executeCommandJob, _jobScheduler).ConfigureAwait(false);

            // Assert
            var start = DateTimeOffset.Now;

            while (DateTimeOffset.Now < start + TimeSpan.FromSeconds(20))
            {
                var testAggregate = await AggregateStore.LoadAsync <ThingyAggregate, ThingyId>(testId, CancellationToken.None).ConfigureAwait(false);

                if (!testAggregate.IsNew)
                {
                    await AssertJobIsSuccessfullAsync(jobId).ConfigureAwait(false);

                    Assert.Pass();
                }

                await Task.Delay(TimeSpan.FromSeconds(0.2)).ConfigureAwait(false);
            }

            Assert.Fail("Aggregate did not receive the command as expected");
        }
Example #2
0
        public Task ScheduleAsync(ICommand command, TimeSpan delay, CancellationToken cancellationToken)
        {
            var publishCommandJob = PublishCommandJob.Create(
                command,
                _commandDefinitionService,
                _jsonSerializer);

            return(_jobScheduler.ScheduleAsync(publishCommandJob, delay, cancellationToken));
        }
Example #3
0
        public Task ScheduleAsync(ICommand command, DateTimeOffset runAt, CancellationToken cancellationToken)
        {
            var publishCommandJob = PublishCommandJob.Create(
                command,
                _commandDefinitionService,
                _jsonSerializer);

            return(_jobScheduler.ScheduleAsync(publishCommandJob, runAt, cancellationToken));
        }
Example #4
0
        public async Task Flow()
        {
            using (var resolver = EventFlowOptions.New
                                  .AddDefaults(EventFlowTestHelpers.Assembly)
                                  .UseHangfireJobScheduler()
                                  .CreateResolver(false))
            {
                GlobalConfiguration.Configuration
                .UseSqlServerStorage(_msSqlDatabase.ConnectionString.Value)
                .UseActivator(new EventFlowResolverActivator(resolver));

                using (new BackgroundJobServer())
                {
                    // Arrange
                    var testId            = ThingyId.New;
                    var pingId            = PingId.New;
                    var jobScheduler      = resolver.Resolve <IJobScheduler>();
                    var eventStore        = resolver.Resolve <IEventStore>();
                    var executeCommandJob = PublishCommandJob.Create(new ThingyPingCommand(testId, pingId), resolver);

                    // Act
                    await jobScheduler.ScheduleNowAsync(executeCommandJob, CancellationToken.None).ConfigureAwait(false);

                    // Assert
                    var start = DateTimeOffset.Now;
                    while (DateTimeOffset.Now < start + TimeSpan.FromSeconds(20))
                    {
                        var testAggregate = await eventStore.LoadAggregateAsync <ThingyAggregate, ThingyId>(testId, CancellationToken.None).ConfigureAwait(false);

                        if (!testAggregate.IsNew)
                        {
                            Assert.Pass();
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(0.2));
                    }
                    Assert.Fail();
                }
            }
        }
Example #5
0
        public async Task Flow()
        {
            using (var resolver = EventFlowOptions.New
                                  .AddDefaults(EventFlowTestHelpers.Assembly)
                                  .CreateResolver(false))
            {
                // Arrange
                var testId            = TestId.New;
                var pingId            = PingId.New;
                var jobScheduler      = resolver.Resolve <IJobScheduler>();
                var eventStore        = resolver.Resolve <IEventStore>();
                var executeCommandJob = PublishCommandJob.Create(new PingCommand(testId, pingId), resolver);

                // Act
                await jobScheduler.ScheduleNowAsync(executeCommandJob, CancellationToken.None).ConfigureAwait(false);

                // Assert
                var testAggregate = await eventStore.LoadAggregateAsync <TestAggregate, TestId>(testId, CancellationToken.None).ConfigureAwait(false);

                testAggregate.IsNew.Should().BeFalse();
            }
        }