public async Task ShouldReturnSameNumberOfRecordsAsAdded() { // Arrange var userOne = new User(new Guid("00000000-0000-0000-0000-000000000001"), "Sarah", "Smith"); var userTwo = new User(new Guid("00000000-0000-0000-0000-000000000002"), "Jenny", "Ross"); var userThree = new User(new Guid("00000000-0000-0000-0000-000000000003"), "Michael", "Bailey"); var getUsersQuery = new GetUsers.Query(); await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { dbContext.Add(userOne); dbContext.Add(userTwo); dbContext.Add(userThree); dbContext.SaveChanges(); } // Act await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { var bugs = await new GetUsers.Handler(dbContext, _mapper) .Handle(getUsersQuery, It.IsAny <CancellationToken>()); // Assert bugs.Count.Should().Be(3, "because three records were added to the database so three should have been returned"); } }
public async Task ShouldReturnOnlyOneRecordWithAMatchingId() { // Arrange var user = new User(new Guid("00000000-0000-0000-0000-000000000001"), "Sarah", "Smith"); var bugOne = new Bug("This is bug one", "BugOne", "New", user.UserId); var bugTwo = new Bug("This is big two", "BugTwo", "Closed", user.UserId); var getBugQuery = new GetBug.Query(1); await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { dbContext.Add(user); dbContext.Add(bugOne); dbContext.Add(bugTwo); dbContext.SaveChanges(); } // Act await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { var bug = await new GetBug.Handler(dbContext, _mapper) .Handle(getBugQuery, It.IsAny <CancellationToken>()); // Assert bug.Title.Should().Be(bugOne.Title, "the retrieved bug should be the same as the one we saved."); } }
public async Task ShouldReturnSameNumberOfRecordsAsAdded() { // Arrange var user = new User(new Guid("00000000-0000-0000-0000-000000000001"), "Sarah", "Smith"); var bugOne = new Bug("This is bug one", "BugOne", "New", user.UserId); var bugTwo = new Bug("This is big two", "BugTwo", "Closed", user.UserId); var getBugsQuery = new GetBugs.Query(); await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { dbContext.Add(user); dbContext.Add(bugOne); dbContext.Add(bugTwo); dbContext.SaveChanges(); } // Act await using (var dbContext = new BugTraqContext(_inMemoryDbOptions)) { var bugs = await new GetBugs.Handler(dbContext, _mapper) .Handle(getBugsQuery, It.IsAny <CancellationToken>()); // Assert bugs.Count.Should().Be(2, "because two records were added to the database so two should have been returned"); } }
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 AddedRecordsShouldBePersisted() { // Arrange var userOneCommand = new AddUser.Command { FirstName = "Sarah", Surname = "Smith" }; var userTwoCommand = new AddUser.Command { FirstName = "Michael", Surname = "Bailey" }; // Act await using var dbContext = new BugTraqContext(_inMemoryDbOptions); await new AddUser.Handler(dbContext).Handle(userOneCommand, It.IsAny <CancellationToken>()); await new AddUser.Handler(dbContext).Handle(userTwoCommand, It.IsAny <CancellationToken>()); // Assert dbContext.Users.Count().Should().Be(2, "we added two records to the database"); }
public Handler(BugTraqContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public Handler(BugTraqContext context) { _context = context; }