public void TaxJarServiceTest() { var taxJarService = new TaxJarCalculator(); Assert.IsTrue(taxJarService.client != null, "TaxJar Client is not created"); Assert.IsTrue(!string.IsNullOrEmpty(taxJarService.client.apiToken), "TaxJar ApiKey is invalid"); }
public async Task GetTaxOnOrderTest() { var httpMessageHandlerMock = new HttpMessageHandlerMock(); var calc = new TaxJarCalculator(httpMessageHandlerMock, "testKey"); var order = new Order() { from_country = "US", from_zip = "07001", from_state = "NJ", to_country = "US", to_zip = "07446", to_state = "NJ", amount = 16.50, shipping = 1.5, line_items = new List <LineItem> { new LineItem() { quantity = 1, unit_price = 15.0, product_tax_code = "31000" } } }; var tax = await calc.GetTaxOnOrderAsync(order); Assert.AreEqual(tax.amount_to_collect, 1.09); }
public void TestGetRatesForZipCodeOnlyAsync() { var service = new TaxJarCalculator(); var actual = service.GetRatesForLocationAsync("30009").GetAwaiter().GetResult(); Assert.AreEqual("0.0775", actual.rate.combined_rate); }
public void Setup() { calc = new TaxJarCalculator(); calc.ApiProfile = TestEngine.GetProfiles()[calc.ProfileName]; calc_bad = new TaxJarCalculator(); //Note that calc_bad does not have an ApiProfile set. This would occur if the ApiProfile configuration in the service was incorrect or missing }
public async Task GetTaxRate_WhenUnsuccessful_ReturnsError() { var taxJar = new TaxJarCalculator(); var res = await taxJar.GetTaxRate(MakeInvalidRateRequest()); Assert.IsFalse(res.success); Assert.IsNotNull(res.message); Assert.IsNull(res.rate); }
public async Task CalculateTax_WhenUnsuccessful_ReturnsError() { var taxJar = new TaxJarCalculator(); var res = await taxJar.CalculateTax(MakeInvalidTaxRequest()); Assert.IsFalse(res.success); Assert.IsNotNull(res.message); Assert.IsNull(res.tax); }
public async Task GetRateTest() { var httpMessageHandlerMock = new HttpMessageHandlerMock(); var calc = new TaxJarCalculator(httpMessageHandlerMock, "testKey"); var rate = await calc.GetRateAsync("90404"); Assert.AreEqual(rate.state_rate, 0.0625); }
public async Task GetTaxRate_WhenSuccessful_ReturnsRate() { var taxJar = new TaxJarCalculator(); var res = await taxJar.GetTaxRate(MakeValildRateRequest()); Assert.IsTrue(res.success); Assert.IsTrue(string.IsNullOrEmpty(res.message)); Assert.IsNotNull(res.rate); Assert.IsTrue(res.rate.CombinedRate > 0); }
public async Task CalculateTax_WhenSuccessful_ReturnsTax() { var taxJar = new TaxJarCalculator(); var res = await taxJar.CalculateTax(MakeValidTaxRequest()); Assert.IsTrue(res.success); Assert.IsTrue(string.IsNullOrEmpty(res.message)); Assert.IsNotNull(res.tax); Assert.IsTrue(res.tax.AmountToCollect > 0); }
public void ConfigureServices(IServiceCollection services) { // Had I had to build out this project more I would probably do more research into how to implement a container in the class library // itself and instantiate a version of that instead that would handle the rest of the DI for that library. var taxJarCalculator = new TaxJarCalculator(new HttpClientHandler(), Configuration["TaxJarApiKey"]); services.AddSingleton(new TaxServiceWorker(taxJarCalculator)); services.AddControllersWithViews().AddNewtonsoftJson(); }
public async Task GetTaxRateForLocationTest() { var taxJarService = new TaxJarCalculator(); var toZip = "33458"; var result = await taxJarService.GetRateForLocation(toZip); Assert.IsTrue(result != default, "Tax Rate should not be zero"); Assert.IsTrue(result == 0.065m, "Jupiter Tax Rate should be 0.065"); }
public TaxJarCalculatorIntegrationTest() { var client = new HttpClient(); client.BaseAddress = new Uri("https://api.taxjar.com"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "API Goes Here"); ITaxJarRateLocationFactory rateLocationFactory = new TaxJarRateLocationHttpFactory(client); _taxJarCalculator = new TaxJarCalculator(client, rateLocationFactory); }
public void CalculateTaxesForAnOrder_ThrowException_WhenOrderIsNull() { //Arrange var taxCalculator = new TaxJarCalculator(); //Act var result = taxCalculator.CalculateTheTaxesForAnOrder(null); //Assert Assert.Equal("Order is invalid. (Parameter 'order')", result.Exception?.InnerException?.Message); }
public void GetTheTaxRatesForALocation_Should_ThrowException_WhenZipCodeIsNull() { //Arrange string zipCode = ""; var taxCalculator = new TaxJarCalculator(); //Act var result = taxCalculator.GetTheTaxRatesForALocation(zipCode, null, null, null, null); //Assert Assert.Equal("Zip code is required. (Parameter 'zip')", result.Exception?.InnerException?.Message); }
public TaxJarCalculatorTest() { _mockHttpMessageHandler = new Mock <HttpMessageHandler>(); var client = new HttpClient(_mockHttpMessageHandler.Object); client.BaseAddress = new Uri("https://api.taxjar.com"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "TOKEN GOES HERE"); ITaxJarRateLocationFactory rateLocationFactory = new TaxJarRateLocationHttpFactory(client); _taxJarCalculator = new TaxJarCalculator(client, rateLocationFactory); }
public void GetTheTaxRatesForALocation_Should_ThrowException_WhenCountryCodeIsNotEqual2Characters() { //Arrange string zipCode = "99010"; string country = "USA"; var taxCalculator = new TaxJarCalculator(); //Act var result = taxCalculator.GetTheTaxRatesForALocation(zipCode, country, null, null, null); //Assert Assert.Equal("Country code should be 2 characters. (Parameter 'country')", result.Exception?.InnerException?.Message); }
public void GetTheTaxRatesForALocation_Should_ThrowException_WhenZipCodeIsInAWrongFormatForCA() { //Arrange string zipCode = "V5K0AX1"; string country = "CA"; var taxCalculator = new TaxJarCalculator(); //Act var result = taxCalculator.GetTheTaxRatesForALocation(zipCode, country, null, null, null); //Assert Assert.Equal("Zip code format for CA is not correct. (Parameter 'validZipCode')", result.Exception?.InnerException?.Message); }
public void CalculateTaxesForAnOrder_ThrowException_WhenToCountryIsNull() { //Arrange var taxCalculator = new TaxJarCalculator(); var order = new Order { ToCountry = null }; //Act var result = taxCalculator.CalculateTheTaxesForAnOrder(order); //Assert Assert.Equal("to_country is a required parameter. (Parameter 'ToCountry')", result.Exception?.InnerException?.Message); }
public void CalculateTaxesForAnOrder_ThrowException_WhenCountryIsUSorCAToStateIsNull() { //Arrange var taxCalculator = new TaxJarCalculator(); var order = new Order { ToCountry = "US", Shipping = 1.5f }; //Act var result = taxCalculator.CalculateTheTaxesForAnOrder(order); //Assert Assert.Equal("to_state is a required parameter when country is US or CA. (Parameter 'ToState')", result.Exception?.InnerException?.Message); }
public async Task CalculateTaxesForZeroValueOrderTest() { var taxJarService = new TaxJarCalculator(); var order = new Models.Order() { FromState = "FL", Country = "US", ToState = "FL", ToZip = "33458" }; var result = await taxJarService.CalculateTaxesForOrder(order); Assert.IsTrue(result == default, "Tax should be zero"); }
public void TestGetOrderTaxes() { var service = new TaxJarCalculator(); var request = new TaxesRequest { from_country = "US", from_state = "NJ", from_zip = "07001", to_country = "US", to_zip = "07446", to_state = "NJ", shipping = 1.5, amount = 16.50 }; var actual = service.GetTaxsForOrderAsync(request).GetAwaiter().GetResult(); Assert.AreEqual(1.19, actual.tax.amount_to_collect); }
public async Task CalculateTaxesForOrderTest() { var taxJarService = new TaxJarCalculator(); var order = new Models.Order() { FromState = "FL", Country = "US", ToState = "FL", ToZip = "33458" }; order.AddProduct(new Product() { Price = 10m }); var result = await taxJarService.CalculateTaxesForOrder(order); Assert.IsTrue(result != default, "Tax should not be zero"); Assert.IsTrue(result == 0.65m, "Tax on $10 should be 65c"); }
public void InitializeClass() { client = new HttpClient(); taxJarCalculator = new TaxJarCalculator(client); taxService = new TaxService(taxJarCalculator); }