Ejemplo n.º 1
0
        public async Task product_service_trolleytotal_throws_exception_when_apiresourceproxy_throws_an_exception()
        {
            // Arrange
            _apiResourceProxy.GetTrolleyCalculator(Arg.Any <TrolleyTotalRequest>()).Returns <Decimal>(x => throw new HttpRequestException());

            // Act, Assert
            var result = await Assert.ThrowsAsync <HttpRequestException>(() => _sut.TrolleyTotal(new TrolleyTotalRequest()));
        }
Ejemplo n.º 2
0
        public async void get_trolley_calculator_should_call_the_correct_endpoint()
        {
            // Arrange
            MockHttpMessageHandler.Response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("2", new ASCIIEncoding(), "application/json")
            };

            // Act
            await _sut.GetTrolleyCalculator(new TrolleyTotalRequest());

            // Assert
            MockHttpMessageHandler.Request.RequestUri.PathAndQuery.Should()
            .Be($"/api/resource/trolleyCalculator?token={Token}");
        }
Ejemplo n.º 3
0
        public void apiresourceproxy_should_throw_exception_if_get_trolley_calculator_error_response(HttpStatusCode errorStatusCode)
        {
            // Assert
            _sut = GetClient <IApiResourceProxy>("http://apihost.com/api/resource/", errorStatusCode);

            // Act
            Func <Task> action = async() => await _sut.GetTrolleyCalculator(new TrolleyTotalRequest());

            // Assert
            action.Should().Throw <HttpRequestException>();

            if (errorStatusCode != HttpStatusCode.Unauthorized && errorStatusCode != HttpStatusCode.BadRequest)
            {
                action = async() => await _sut.GetShopperHistory();

                action.Should().Throw <BrokenCircuitException>();
            }
        }
Ejemplo n.º 4
0
 public async Task <decimal> TrolleyTotal(TrolleyTotalRequest request)
 {
     return(await _apiResourceProxy.GetTrolleyCalculator(request));
 }