public async Task GetWatches_CallsWatchRepositoryWithDefaultValues() { // Arrange var expected = GetWatches(); var mockWatchRepository = new Mock <IWatchRepository>(); mockWatchRepository.Setup(svc => svc.GetWatchesAsync(null, null, null, 0, 20)).ReturnsAsync(expected); var mockApiConfiguration = new Mock <IApiConfiguration>(); mockApiConfiguration.Setup(config => config.ApiPageSizeLimit).Returns(100); mockApiConfiguration.Setup(config => config.ApiDefaultPageSize).Returns(20); var controller = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object); // Act var response = await controller.GetWatchesAsync(); // Assert var actionResult = Assert.IsType <ActionResult <GetListResponse <WatchDto> > >(response); var listResponse = Assert.IsAssignableFrom <GetListResponse <WatchDto> >(actionResult.Value); Assert.Equal(expected.Total, listResponse.Total); Assert.Equal(expected.Count, listResponse.Count); Assert.Equal(expected.PageNumber, listResponse.PageNumber); Assert.Equal(expected.PageSize, listResponse.PageSize); Assert.Equal(expected.Results.Count(), listResponse.Results.Count()); }
public async Task GetWatches_ThrowsBadRequest_ForInvalidPageSize() { // Arrange var mockWatchRepository = new Mock <IWatchRepository>(); var mockApiConfiguration = new Mock <IApiConfiguration>(); mockApiConfiguration.Setup(config => config.ApiPageSizeLimit).Returns(10); var controller = new WatchController(mockWatchRepository.Object, mockApiConfiguration.Object); // Act var ex = await Assert.ThrowsAsync <BadRequestException>(() => controller.GetWatchesAsync(pageSize: 11)); // Assert Assert.Equal("pageSize", ex.Key); Assert.Equal("Wrong value for page size: 11. Page size is expected to be in 1-10 range.", ex.Message); }