public async Task AddBasketItem_ProductNotExistsInBasket_ReturnsBasket( [Frozen] Mock <IBasketApiClient> mockBasketApiClient, [Frozen] Mock <IProductApiClient> mockProductApiClient, [Greedy] BasketService sut, ApplicationUser user, bm.Basket basket, Product product, int quantity ) { //Arrange mockProductApiClient.Setup(_ => _.GetProductAsync(It.IsAny <string>())) .ReturnsAsync(product); mockBasketApiClient.Setup(_ => _.GetBasket(It.IsAny <string>())) .ReturnsAsync(basket); //Act var response = await sut.AddBasketItemAsync( user, product.ProductNumber, quantity ); //Assert response.BuyerId.Should().Be(basket.BuyerId); response.Items.Count.Should().Be(basket.Items.Count + 1); mockBasketApiClient.Verify(_ => _.UpdateBasket(It.IsAny <bm.Basket>())); }
public async Task AddBasketItem_ProductExistsInBasket_ReturnsBasket( [Frozen] Mock <IBasketApiClient> mockBasketApiClient, [Greedy] BasketService sut, ApplicationUser user, bm.Basket basket, List <int> quantityValues ) { //Arrange Dictionary <string, int> quantities = new(); for (int i = 0; i < basket.Items.Count; i++) { quantities.Add(basket.Items[i].Id, quantityValues[i]); } mockBasketApiClient.Setup(_ => _.GetBasket(It.IsAny <string>())) .ReturnsAsync(basket); //Act var resultBasket = await sut.SetQuantities( user, quantities ); //Assert for (int i = 0; i < basket.Items.Count; i++) { resultBasket.Items[i].Quantity.Should().Be(quantityValues[i]); } mockBasketApiClient.Verify(_ => _.UpdateBasket(It.IsAny <bm.Basket>())); }
public async Task GetBasket_BasketExist_ReturnsBasket( [Frozen] Mock <IBasketApiClient> mockClient, [Greedy] BasketService sut, bm.Basket basket ) { //Arrange mockClient.Setup(_ => _.GetBasket(It.IsAny <string>())) .ReturnsAsync(basket); //Act var response = await sut.GetBasketAsync <Basket>(basket.BuyerId); //Assert response.BuyerId.Should().Be(basket.BuyerId); response.Items.Count.Should().Be(basket.Items.Count); }