public OrderTaxInfo CalculateTaxesForOrder(OrderInfo orderInfo) { var taxJarOrder = new TaxJarOrder(orderInfo); var validationErrors = taxJarOrder.ValidationErrors(); if (validationErrors.Any()) { var aggregatedMessage = string.Join(Environment.NewLine, validationErrors); throw new ArgumentException("There is something wrong with the order data", nameof(orderInfo), new Exception(aggregatedMessage)); } using (var client = clientFactory.CreateClient("TaxJar")) { var content = new StringContent(JsonConvert.SerializeObject(taxJarOrder), Encoding.UTF8, "application/json"); try { var response = client.PostAsync("taxes", content) .ConfigureAwait(false) .GetAwaiter() .GetResult(); if (response.IsSuccessStatusCode) { var result = ParseJsonResponseIntoAnonymousType(response, new { tax = new TaxJarOrderTax() }); return(result.tax.ToOrderTaxInfo()); } // log the response error return(null); } catch (Exception) { // logging should be added here // I decided to swallow the exeption instead of bubling it up // this might change depending on how we want to wire the service // to deal with it return(null); } } }
public void OriginalOrderIsValid() { Assert.IsEmpty(validOrder.ValidationErrors()); }