Exemplo n.º 1
0
        public async Task <List <Product> > Sort(SortOption sortOption)
        {
            var products = await _apiResourceProxy.GetProducts();

            var productSorter = _productSorterFactory.GetProductSorter(sortOption);

            return(productSorter.Sort(products));
        }
Exemplo n.º 2
0
        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>();
            }
        }
Exemplo n.º 3
0
        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}");
        }
Exemplo n.º 4
0
        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();
            }
        }