public async Task Test_StartJob_Should_Be_InProgress_With_StartTime() { // arrange var job = new JobFaker().Generate("default,Pending"); await using var dbContext = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>(); await dbContext.Setup(x => x.Jobs, job); var message = new TestStartJobMessage { JobId = job.JobId, StartTime = DateTimeOffset.Now }; // act; await _consumer.Consume(new TestConsumeContext <StartJob>(message)); // assert var actual = DbContextFactory.Instance .CreateDbContext <PortAuthorityDbContext>() .Jobs.SingleOrDefault(j => j.JobId == job.JobId); actual.Should().NotBeNull(); actual.Status.Should().Be(Status.InProgress, because: "job status updated"); actual.StartTime.Should().BeCloseTo(message.StartTime, because: "job start time updated"); }
public async Task Test_StartJob_AlreadyInProgress_Should_noop() { // arrange var job = new JobFaker().Generate("default,InProgress"); await using var dbContext = DbContextFactory.Instance.CreateDbContext <PortAuthorityDbContext>(); await dbContext.Setup(x => x.Jobs, job); var message = new TestStartJobMessage { JobId = job.JobId, StartTime = DateTimeOffset.Now.AddDays(99) }; // act await _consumer.Consume(new TestConsumeContext <StartJob>(message)); // assert var actual = DbContextFactory.Instance .CreateDbContext <PortAuthorityDbContext>() .Jobs.SingleOrDefault(j => j.JobId == job.JobId); actual.Should().NotBeNull(); actual.Status.Should().Be(job.Status); actual.StartTime.Should().BeCloseTo(job.StartTime.Value, because: "job start time should not have changed"); }
public async Task Test_StartJobConsumer_Should_Consume_With_Status_ImProgress() { // arrange var consumerHarness = Consumer <StartJobConsumer>(); var job = new JobFaker().Generate("default,Pending"); await using var dbContext = GetDbContext(); await dbContext.Setup(x => x.Jobs, new [] { job }); var message = new TestStartJobMessage() { JobId = job.JobId, StartTime = DateTimeOffset.Now }; await Harness.Start(); try { // act await Harness.InputQueueSendEndpoint.Send <StartJob>(message); // assert Assert.That(await Harness.Consumed.Any <StartJob>(), "endpoint consumed message"); Assert.That(await consumerHarness.Consumed.Any <StartJob>(), "actual consumer consumed the message"); Assert.That(await Harness.Published.Any <Fault <StartJob> >(), Is.False, "message handled without fault"); await using var actualDbContext = GetDbContext(); var actual = actualDbContext.Jobs.SingleOrDefault(j => j.JobId == message.JobId); actual.Should().NotBeNull(); actual.JobId.Should().Be(message.JobId); actual.Status.Should().Be(Status.InProgress, "job status updated"); actual.StartTime.Should().BeCloseTo(message.StartTime, because: "job start time updated"); } finally { await Harness.Stop(); } }