public void QueryingCollectionHandler_ReturnsAllCharactersFromFacade() { var facade = new CharactersFacade(); var characters = facade.Query(); Assert.NotNull(characters); Assert.NotEmpty(characters); var handler = new CharactersQueryHandler(facade); var result = handler.Handle(new CharactersQuery(), new CancellationToken()).GetAwaiter().GetResult(); Assert.NotNull(result); Assert.NotNull(result.Data); Assert.True(result.IsSuccessful); Assert.Equal(characters.Count, result.Data.Count); }
public void QueryingWithPagination() { var queryHandler = new CharactersQueryHandler(new CharactersContext(new DbContextOptionsBuilder().UseSqlServer(_connectionString).Options)); var nonpaginatedResult = queryHandler.Handle(new CharactersQuery(), new CancellationToken()) .GetAwaiter() .GetResult(); Assert.True(nonpaginatedResult.IsSuccessful); int count = nonpaginatedResult.Data.Count; for (int pageSize = 1; pageSize < count + 2; pageSize++) { int requestedPage = 1; do { var paginatedResult = queryHandler .Handle( new CharactersQuery { PaginationOptions = new PaginationOptions { PageNumber = requestedPage, PageSize = pageSize } }, new CancellationToken()) .GetAwaiter() .GetResult(); Assert.True(paginatedResult.IsSuccessful); Assert.Equal(count, paginatedResult.Total); if (paginatedResult.Data.Count < pageSize) { Assert.True(requestedPage == paginatedResult.CurrentPage); } else { Assert.True(requestedPage >= paginatedResult.CurrentPage); } } while (count > requestedPage++ *pageSize); } }