public async Task <List <Product> > Sort(SortOption sortOption) { var products = await _apiResourceProxy.GetProducts(); var productSorter = _productSorterFactory.GetProductSorter(sortOption); return(productSorter.Sort(products)); }
public void apiresourceproxy_should_throw_exception_if_get_products_error_response(HttpStatusCode errorStatusCode) { // Assert _sut = GetClient <IApiResourceProxy>("http://apihost.com/api/resource/", errorStatusCode); // Act Func <Task> action = async() => await _sut.GetProducts(); // Assert action.Should().Throw <HttpRequestException>(); if (errorStatusCode != HttpStatusCode.Unauthorized && errorStatusCode != HttpStatusCode.BadRequest) { action = async() => await _sut.GetProducts(); action.Should().Throw <BrokenCircuitException>(); } }
public async void get_products_should_call_the_correct_endpoint() { // Act await _sut.GetProducts(); // Assert MockHttpMessageHandler.Request.RequestUri.PathAndQuery.Should() .Be($"/api/resource/products?token={Token}"); }
public async Task product_service_sort_should_return_correct_products(SortOption sortOption) { // Arrange _apiResourceProxy.GetProducts().Returns(Mocks.MockData.GetProducts()); _apiResourceProxy.GetShopperHistory().Returns(Mocks.MockData.GetShopperHistory()); // Act var result = await _sut.Sort(sortOption); // Assert result.Should().BeEquivalentTo(Mocks.MockData.GetProductSorted(sortOption)); if (sortOption != SortOption.Recommended) { // Shopper history only called for recommended _apiResourceProxy.Received(0).GetShopperHistory(); } else { _apiResourceProxy.Received(1).GetShopperHistory(); } }