public async Task <double> TrolleyCalculator(TrolleyItems items) { Uri endpointUri = new Uri(_readConfig.ReadBaseUrl() + _readConfig.ReadTrollyCaclulator()); endpointUri = endpointUri.AddQuery("Token", _readConfig.UserId()); var requestMessage = new HttpRequestMessage(HttpMethod.Post, endpointUri) { Content = new StringContent(_serializer.Serialise(items), Encoding.UTF8, "application/json") }; _logger.Information("Sending request to {uri}", endpointUri); var response = await _client.SendAsync(requestMessage); if (response.StatusCode != HttpStatusCode.OK) { _logger.Error("Error while sending request to {uri}", endpointUri); throw new HttpResponseException(response); } var contents = await response.Content.ReadAsStringAsync(); double total; double.TryParse(contents, out total); return(total); }
public async Task <List <Product> > GetProductsAsync() { Uri endpointUri = new Uri(_readConfig.ReadBaseUrl() + _readConfig.ReadProduct()); endpointUri = endpointUri.AddQuery("Token", _readConfig.UserId()); var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpointUri); _logger.Information("Sending request to {uri}", endpointUri); var response = await _client.SendAsync(requestMessage); if (response.StatusCode != HttpStatusCode.OK) { _logger.Error("Product repository exception"); throw new HttpResponseException(response); } var contents = await response.Content.ReadAsStringAsync(); return(_deserializer.Deserialize <List <Product> >(contents)); }
UserId_UserIdNotPresent_ThrowConfigurationErrorsException () { Assert.Throws <ConfigurationErrorsException>(() => _config.UserId()); }