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 <IActionResult> GetUsers() { var query = new GetUsers.Query(); var result = await Mediator.Send(query); return(Ok(result)); }
public async Task <IActionResult> GetUsers(GetUsers.Query query) // this action result similar to a view returns a users collection model to the GetUsers page { var model = await _mediator.Send(query); return(View(model)); }