public async Task CanCreateJob() { // Arrange var expectedJob = new Database.Entities.Job { Id = Guid.NewGuid(), LeagueCode = "LC", StatusCode = System.Net.HttpStatusCode.Created }; using var executionContext = new ExecutionContext <AppDbContext>(true); using (var actionContext = await executionContext.CreateContextAsync()) { var sut = new JobRepository(actionContext.Jobs); // Act sut.Add(expectedJob); await actionContext.SaveChangesAsync(); } // Assert using var assertionContext = await executionContext.CreateContextAsync(); var createdJob = await assertionContext.Jobs .FirstOrDefaultAsync(job => job.Id == expectedJob.Id); createdJob.Should().NotBeNull(); createdJob.Should().BeEquivalentTo(expectedJob); }
public async Task CanCreateJob() { // Arrange var expectedJob = new Models.Job { LeagueCode = "PL" }; var entityJob = new Database.Entities.Job { LeagueCode = "PL", StatusCode = System.Net.HttpStatusCode.Created }; var eventBus = A.Fake <IEventBus>(); var jobRepository = A.Fake <IJobRepository>(); var unitOfWork = A.Fake <IUnitOfWork>(); var mapper = A.Fake <IMapper>(); A.CallTo(() => unitOfWork.JobRepository) .Returns(jobRepository); A.CallTo(() => mapper.Map <Database.Entities.Job>(A <Models.Job> .Ignored)) .Returns(entityJob); var sut = new JobService(eventBus, unitOfWork, mapper); // Act await sut.CreateAsync(expectedJob); // Assert A.CallTo(() => mapper.Map <Database.Entities.Job>(A <Models.Job> .That.Matches( modelJob => modelJob.Id != Guid.Empty && modelJob.StatusCode == System.Net.HttpStatusCode.Accepted && modelJob.LeagueCode == expectedJob.LeagueCode && string.IsNullOrWhiteSpace(modelJob.CallbackUri)))) .MustHaveHappened(); A.CallTo(() => jobRepository.Add(entityJob)) .MustHaveHappened(); A.CallTo(() => eventBus.PublishAsync(A <ImportLeagueCommand> .That.Matches( command => command.Id != Guid.Empty && command.LeagueCode == expectedJob.LeagueCode && string.IsNullOrWhiteSpace(command.CallbackUri)))) .MustHaveHappened(); }