public async Task AddedRecordsShouldBePersisted() { // Arrange var user = new User(new Guid("00000000-0000-0000-0000-000000000001"), "Sarah", "Smith"); var bugOneCommand = new AddBug.Command { Title = "This is bug one", Description = "BugOne", Status = "new", UserId = user.UserId }; var bugTwoCommand = new AddBug.Command { Title = "This is bug two", Description = "BugTwo", Status = "active", UserId = user.UserId }; await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { dbContext.Add(user); dbContext.SaveChanges(); } // Act await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { await new AddBug.Handler(dbContext).Handle(bugOneCommand, It.IsAny <CancellationToken>()); await new AddBug.Handler(dbContext).Handle(bugTwoCommand, It.IsAny <CancellationToken>()); // Assert dbContext.Bugs.Count().Should().Be(2, "we added two records to the database"); } }
public async Task PostBug([FromBody] AddBug.Command bug) { await _mediator.Send(bug); }