public async Task AddProductToCustomerrWishlistAsync_ShouldReturnExistingProduct_WhenProductIsAlreadyInWishlist() { //Arrange string productId = "1bf0f365-fbdd-4e21-9786-da459d78dd1f"; _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); var existingList = new List <WishListProduct>() { new WishListProduct() { ProductId = productId } }; _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(existingList); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var product = await sut.AddProductToCustomerrWishlistAsync(customerId, productId); //Assert Assert.NotNull(product); await _wishlistRepository.DidNotReceive().InsertWishlistProductAsync(Arg.Any <int>(), Arg.Any <WishListProduct>()); Assert.Equal(productId, product.ProductId); }
public async Task AddProductToCustomerrWishlistAsync_ShouldReturnNull_WhenCustomerDoesNotExist() { //Arrange _customerService.GetCustomerAsync(customerId).Returns(nullReturn); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var product = await sut.AddProductToCustomerrWishlistAsync(customerId, "1"); //Assert Assert.Null(product); }
public async Task AddProductToCustomerrWishlistAsync_ShouldCallRepository_WhenCustomerDoesExist() { //Arrange string newProductId = "3"; string existingProductId = "4"; _customerService.GetCustomerAsync(customerId).Returns(existingCustomer); _wishlistRepository.InsertWishlistProductAsync(customerId, Arg.Any <WishListProduct>()).Returns(new WishListProduct()); var wishlistProduct = new WishListProduct() { ProductId = newProductId, Image = "http://images.luizalabs.com/123.png", Price = "30.00", Title = "Product123" }; _productRest.GetProductByIdAsync(newProductId).Returns(wishlistProduct); var existingList = new List <WishListProduct>() { new WishListProduct() { ProductId = existingProductId } }; _wishlistRepository.GetCustomerWishlistAsync(customerId).Returns(existingList); //Act var sut = new WishlistService(_productRest, _customerService, _wishlistRepository); var product = await sut.AddProductToCustomerrWishlistAsync(customerId, newProductId); //Assert Assert.NotNull(product); _ = _wishlistRepository.Received(1).InsertWishlistProductAsync( customerId, Arg.Is <WishListProduct>( x => x.ProductId == wishlistProduct.ProductId && x.Image == wishlistProduct.Image && x.Price == wishlistProduct.Price && x.Title == wishlistProduct.Title )); }