public async Task GetAllDiscountAsync__An_unexpected_internal_error_occurred__Should_throw_Exception() { _discountDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception()); var controller = new DiscountsController(_discountDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAllDiscountsAsync(); await result.Should().ThrowExactlyAsync <Exception>(); }
public async Task GetAllDiscountAsync__At_least_one_element_found__Should_return_200OK_response_with_not_empty_IEnumerable() { _discountDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(_discounts); _mapperMock.Setup(x => x.Map <IEnumerable <DiscountDto> >(It.IsNotNull <IEnumerable <Discount> >())).Returns(_discountDtos.AsEnumerable()); var controller = new DiscountsController(_discountDbServiceMock.Object, _logger, _mapperMock.Object); var result = await controller.GetAllDiscountsAsync(); (result as ObjectResult).StatusCode.Should().Be(200); (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <DiscountDto>).Should().NotBeEmpty(); }
public async Task GetAllDiscountAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException() { // Example of these errors: database does not exist, table does not exist etc. _discountDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new InternalDbServiceException()); var controller = new DiscountsController(_discountDbServiceMock.Object, _logger, _mapperMock.Object); Func <Task> result = async() => await controller.GetAllDiscountsAsync(); await result.Should().ThrowExactlyAsync <InternalDbServiceException>(); }