コード例 #1
0
        async public Task <TaxRatesResponse> GetTaxRatesForLocation(TaxRatesRequest taxRateRequest)
        {
            if (taxRateRequest == null)
            {
                throw new ArgumentNullException("taxRateRequest");
            }

            if (string.IsNullOrWhiteSpace(taxRateRequest.Zip))
            {
                throw new ArgumentException("Param Zip is required for US.", nameof(taxRateRequest));
            }

            try
            {
                var taxRateRequestUri = BuildTaxRateRequestUri(taxRateRequest);

                var taxRateJarResponse = await TaxJarHttpClientProvider.GetAsync <TaxRatesJarResponse>(taxRateRequestUri, Constants.API_KEY);

                return(taxRateJarResponse.Rate);
            }
            catch (Exception ex)
            {
                throw new TaxCalculatorException(ex.Message);
            }
        }
コード例 #2
0
        private string BuildTaxRateQueryString(TaxRatesRequest taxRateRequest)
        {
            var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);

            if (!string.IsNullOrWhiteSpace(taxRateRequest.Country))
            {
                queryString.Add("country", taxRateRequest.Country);
            }

            if (!string.IsNullOrWhiteSpace(taxRateRequest.State))
            {
                queryString.Add("state", taxRateRequest.State);
            }

            if (!string.IsNullOrWhiteSpace(taxRateRequest.City))
            {
                queryString.Add("city", taxRateRequest.City);
            }

            if (!string.IsNullOrWhiteSpace(taxRateRequest.Street))
            {
                queryString.Add("street", taxRateRequest.Street);
            }

            // Since the actual object is an HttpValueCollection, calling ToString will format the collection as a URL-encoded query string.
            return(queryString.ToString());
        }
コード例 #3
0
        public async Task GetTaxRate_Valid_EmptyZip_Country_City_US()
        {
            // arrange
            var taxRateRequest = new TaxRatesRequest()
            {
                Zip     = "",
                Country = "US",
                City    = "Santa Monica"
            };

            // act
            await taxCalculator.GetTaxRatesForLocation(taxRateRequest);
        }
コード例 #4
0
        public async Task GetTaxRate_Valid_Zip_Country_City_Street_US()
        {
            // arrange
            var taxRateRequest = new TaxRatesRequest()
            {
                Zip     = "98109",
                Country = "US",
                City    = "Seattle",
                Street  = "400 Broad St"
            };

            var expectedCountryRate = "0.0";

            // act
            var taxRateResponse = await taxCalculator.GetTaxRatesForLocation(taxRateRequest);

            // assert
            Assert.AreEqual(expectedCountryRate, taxRateResponse.CountryRate);
        }
コード例 #5
0
        public async Task GetTaxRate_Valid_Zip_Country_City_CA()
        {
            // arrange
            var taxRateRequest = new TaxRatesRequest()
            {
                Zip     = "V5K0A1",
                Country = "CA",
                City    = "Vancouver"
            };

            var expectedCity         = "Vancouver";
            var expectedCombinedRate = "0.12";

            // act
            var taxRateResponse = await taxCalculator.GetTaxRatesForLocation(taxRateRequest);

            // assert
            Assert.AreEqual(expectedCity, taxRateResponse.City);
            Assert.AreEqual(expectedCombinedRate, taxRateResponse.CombinedRate);
        }
コード例 #6
0
        public async Task GetTaxRate_Valid_Zip_Country_City_US()
        {
            // arrange
            var taxRateRequest = new TaxRatesRequest()
            {
                Zip     = "90404",
                Country = "US",
                City    = "Santa Monica"
            };

            var expectedCombinedRate = "0.1025";
            var expectedStateRate    = "0.0625";
            var expectedZip          = "90404";

            // act
            var taxRateResponse = await taxCalculator.GetTaxRatesForLocation(taxRateRequest);

            // assert
            Assert.AreEqual(expectedCombinedRate, taxRateResponse.CombinedRate);
            Assert.AreEqual(expectedStateRate, taxRateResponse.StateRate);
            Assert.AreEqual(expectedZip, taxRateResponse.Zip);
        }
コード例 #7
0
        private string BuildTaxRateRequestUri(TaxRatesRequest taxRateRequest)
        {
            string taxRateQueryString = BuildTaxRateQueryString(taxRateRequest);

            return($"rates/{taxRateRequest.Zip}?{taxRateQueryString}");
        }
コード例 #8
0
 async public Task <TaxRatesResponse> GetTaxRatesForLocation(TaxRatesRequest taxRateRequest)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
ファイル: TaxService.cs プロジェクト: jordenys/tax-calculator
 async public Task <TaxRatesResponse> GetTaxRatesForLocation(TaxRatesRequest taxRateRequest)
 {
     // Do some businees logic here
     return(await this._taxCalculator.GetTaxRatesForLocation(taxRateRequest));
 }