public async Task Should_ReturnBasket_When_BasketExists() { // Arrange var cart = Task.FromResult(Fixture.Generate <Cart>()); CartReposioryMock .Setup(m => m.GetAsync(It.IsAny <Func <Cart, bool> >())) .Returns(cart); foreach (var item in cart.Result.Items) { ProductReposioryMock .Setup(m => m.GetAsync(It.IsAny <Func <Product, bool> >())) .ReturnsAsync(Fixture.Generate <Product>(constraints: new { Identifier = item.ProductId })); } CartMapperMock.Setup(m => m.Map <CartDto>(cart.Result)) .Returns(new CartDto() { Name = cart.Result.Name }); MapperProviderMock.Setup(m => m.Provide()) .Returns(CartMapperMock.Object); var controller = InitController(); // Act var response = await controller.GetAsync(cart.Result.Name); // Assert response.AssertResponseType <OkObjectResult>(200) .Which.Value.Should().BeAssignableTo <CartDto>() .Which.Name.Should().Be(cart.Result.Name); }
public async Task Should_Reutn500_When_ProductFromBasketDoesNotExistInRepository() { CartReposioryMock .Setup(x => x.GetAsync(It.IsAny <Func <Cart, bool> >())) .ReturnsAsync(Fixture.Generate <Cart>()); CartMapperMock.Setup(x => x.Map <CartDto>(It.IsAny <Cart>())) .Throws(new ProdcutNotFoundException()); MapperProviderMock.Setup(x => x.Provide()) .Returns(CartMapperMock.Object); var controller = InitController(); // Act var response = await controller.GetAsync("cart1"); // Assert response.AssertResponseType <NotFoundObjectResult>(404) .AssertMessage("Cart product not found"); }