public async Task Test_StartJob_AlreadyInProgress_Should_noop()
        {
            // arrange
            var job  = new JobFaker().Generate("default,InProgress");
            var task = new SubtaskFaker().SetJob(job).Generate("defaults,InProgress");

            await using var dbContext = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>();
            await dbContext.Setup(x => x.Jobs, job);

            await dbContext.Setup(x => x.Tasks, task);

            var message = new TestStartSubtaskMessage
            {
                TaskId    = task.TaskId,
                StartTime = DateTimeOffset.Now.AddDays(99)
            };

            // act
            await _consumer.Consume(new TestConsumeContext <StartSubtask>(message));

            // assert
            var actual = DbContextFactory.Instance
                         .CreateDbContext <PortAuthorityDbContext>()
                         .Tasks.SingleOrDefault(t => t.TaskId == task.TaskId);

            actual.Should().NotBeNull();
            actual.Status.Should().Be(task.Status, "task status should not have changed");
            actual.StartTime.Should().BeCloseTo(task.StartTime.Value, because: "task start time should not have changed");
        }
        public async Task Test_StartSubtask_Should_Be_InProgress_With_StartTime()
        {
            // arrange
            var job  = new JobFaker().Generate("default,InProgress");
            var task = new SubtaskFaker().SetJob(job).Generate("defaults,Pending");

            await using var dbContext = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>();
            await dbContext.Setup(x => x.Jobs, job);

            await dbContext.Setup(x => x.Tasks, task);

            var message = new TestStartSubtaskMessage
            {
                TaskId    = task.TaskId,
                StartTime = DateTimeOffset.Now
            };

            // act
            await _consumer.Consume(new TestConsumeContext <StartSubtask>(message));

            // assert
            var actual = DbContextFactory.Instance
                         .CreateDbContext <PortAuthorityDbContext>()
                         .Tasks.SingleOrDefault(t => t.TaskId == task.TaskId);

            actual.Should().NotBeNull();
            actual.Status.Should().Be(Status.InProgress, because: "sub-task status updated");
            actual.StartTime.Should().BeCloseTo(message.StartTime, because: "sub-task start time updated");
        }
예제 #3
0
        public async Task Test_StartSubtaskConsumer_Should_Consume_With_Status_InProgress()
        {
            // arrange
            var consumerHarness = Consumer <StartSubtaskConsumer>();

            var job  = new JobFaker().Generate("default,Pending");
            var task = new SubtaskFaker().SetJob(job).Generate("default,Pending");

            await using var dbContext = GetDbContext();
            await dbContext.Setup(x => x.Jobs, job);

            await dbContext.Setup(x => x.Tasks, task);

            var message = new TestStartSubtaskMessage()
            {
                TaskId    = task.TaskId,
                StartTime = DateTimeOffset.Now
            };

            await Harness.Start();

            try
            {
                // act
                await Harness.InputQueueSendEndpoint.Send <StartSubtask>(message);

                // assert
                Assert.That(await Harness.Consumed.Any <StartSubtask>(), "endpoint consumed message");
                Assert.That(await consumerHarness.Consumed.Any <StartSubtask>(), "actual consumer consumed the message");
                Assert.That(await Harness.Published.Any <Fault <StartSubtask> >(), Is.False, "message handled without fault");

                await using var actualDbContext = GetDbContext();
                var actual = actualDbContext.Tasks.SingleOrDefault(t => t.TaskId == task.TaskId);

                actual.Should().NotBeNull();
                actual.TaskId.Should().Be(task.TaskId);
                actual.Status.Should().Be(Status.InProgress, "job status updated");
                actual.StartTime.Should().BeCloseTo(message.StartTime, because: "job start time updated");
            }
            finally
            {
                await Harness.Stop();
            }
        }