public void GetTaxRateNullCalculatorTest() { TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US", Zip = "05495-2086" }; Calculators.TaxJar taxJar = null; using (var service = TaxCalculationLibrary.Service.Factory.GetTaxService(taxJar)) { try { TaxJarRateResponse result = service.GetTaxRate(taxRateRequest); Assert.Fail("Should throw exception"); } catch (Exception ex) { Assert.IsNotNull(ex); } } }
public void GetTaxRateBadRequestNoZipTest() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; string apikey = "5da2f821eee4035db4771edab942a4cc"; TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US" }; Calculators.TaxJar taxJar = new Calculators.TaxJar(apikey, "", taxRateApiendpoint); using (var service = Factory.GetTaxService(taxJar)) { try { TaxJarRateResponse result = service.GetTaxRate(taxRateRequest); Assert.Fail("Should throw exception"); } catch (Exception ex) { Assert.IsNotNull(ex); } } }
public void GetTaxRateBadCalculatorNoAPIKeyTest() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US", Zip = "05495-2086" }; TaxCalculationLibrary.Calculators.TaxJar taxJar = new TaxCalculationLibrary.Calculators.TaxJar("", "", taxRateApiendpoint); using (var service = TaxCalculationLibrary.Service.Factory.GetTaxService(taxJar)) { try { TaxJarRateResponse result = service.GetTaxRate(taxRateRequest); Assert.Fail("Should throw exception"); } catch (Exception ex) { Assert.IsNotNull(ex); } } }
public async Task <TaxRateModel> GetTaxRates(TaxRateRequest request) { TaxJarRateResponse response = null; TaxRateModel mapped = mapper.Map <TaxRateModel>(request); if (request == null) { throw new ArgumentException(nameof(request), "Request cannot be null. Zip code is required."); } if (string.IsNullOrEmpty(request.Zip)) { throw new ArgumentException(nameof(request.Zip), "Zip Code is required."); } if (!string.IsNullOrEmpty(request.City) || !string.IsNullOrEmpty(request.State) || !string.IsNullOrEmpty(request.Street) || !string.IsNullOrEmpty(request.Country)) { response = await taxRepository.Get <TaxRateModel, TaxJarRateResponse>(mapped); } else { response = await taxRepository.Get <TaxJarRateResponse>(request.Zip); } return(mapper.Map <TaxRateModel>(response)); }
public void GetTaxRateNullRequestTest() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; string apikey = "5da2f821eee4035db4771edab942a4cc"; Calculators.TaxJar taxJar = new Calculators.TaxJar(apikey, "", taxRateApiendpoint); try { TaxJarRateResponse result = taxJar.GetTaxRate(null); Assert.Fail("Should throw exception"); } catch (Exception ex) { Assert.IsNotNull(ex); } }
public void GetTaxRateGoodRequestTest() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; string apikey = "5da2f821eee4035db4771edab942a4cc"; TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US", Zip = "05495-2086" }; Calculators.TaxJar taxJar = new Calculators.TaxJar(apikey, "", taxRateApiendpoint); try { TaxJarRateResponse result = taxJar.GetTaxRate(taxRateRequest); Assert.IsNotNull(result); } catch (Exception ex) { Assert.Fail(ex.Message); } }