public async Task <List <ProductResponse> > GetProducts() { try { return(await _client.GetProducts()); } catch (Exception e) { throw e; } }
public async Task <IActionResult> Index() { var cart = new CartViewModel { CartLines = await _cartLineApiClient.GetCartLines(), AllProducts = await _productApiClient.GetProducts() }; cart.TotalPrice = cart.CartLines.Sum(cl => cl.TotalPrice); return(View(cart)); }
public void GetProductList() { //Arrange _mockProviderService.UponReceiving("a request to get list of first five product items.") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Headers = new Dictionary <string, object> { { "Accept", "application/json" } }, Path = "/product/productlist" }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new[] { new { id = "430c659d-0065-4abc-8bc3-9c5b30ecd717", name = "Product-1", description = "1 Product description.", image = "", price = 0 }, new { id = "c6502d76-83fd-44d5-b84d-987d28933f0a", name = "Product-2", description = "2 Product description.", image = "", price = 0 }, new { id = "932cc010-7838-4d8e-945d-41d3a08b58c0", name = "Product-3", description = "3 Product description.", image = "", price = 0 }, new { id = "a37fc4c3-a053-4229-81a7-44ac5db00530", name = "Product-4", description = "4 Product description.", image = "", price = 0 }, new { id = "e0d30816-5362-41c5-9f9a-2c1bf3c12d10", name = "Product-5", description = "5 Product description.", image = "", price = 100 } } }); var consumer = new ProductApiClient(_serviceBaseUri); //Act var result = consumer.GetProducts(); //Assert Assert.True(result.Any()); _mockProviderService.VerifyInteractions(); }
public async Task <IActionResult> Index() { return(View(await _productApiClient.GetProducts())); }