Exemplo n.º 1
0
        public TaxResultsUSA FindTaxRates(TaxSearchUSA searchBy, ITaxRatesRepositoryUSA repo)
        {
            _logger.Verbose($"{this.GetType().Name} IN FindTaxRates");

            var check = searchBy.IsValid();

            if (!check.validStatus)
            {
                _logger.Error(check.whyNot);
                throw new ArgumentException(check.whyNot);
            }

            var zipcode  = int.Parse(searchBy.Zipcode);
            var zipPlus4 = int.Parse(searchBy.ZipPlus4);

            var fetchedRecord = repo.FetchByZipcode(zipcode, zipPlus4, searchBy.OnDate);

            if (fetchedRecord == null)
            {
                var notFoundMsg = string.Format(
                    "TaxRates for {0}-{1} were not found"
                    , zipcode.ToString("00000")
                    , zipPlus4.ToString("0000")
                    );
                _logger.Error(notFoundMsg);
                throw new KeyNotFoundException(notFoundMsg);
            }

            var results = new TaxResultsUSA()
            {
                TaxRateState    = fetchedRecord.TaxRateState
                , TaxRateCounty = fetchedRecord.TaxRateCounty
                , TaxRateCity   = fetchedRecord.TaxRateCity
                , TaxRateLocal1 = fetchedRecord.TaxRateLocal1
                , TaxRateLocal2 = fetchedRecord.TaxRateLocal2
            };

            return(results);
        }
Exemplo n.º 2
0
        public void FindTaxRatesUSAService()
        {
            TaxSearchUSA  search  = null;
            TaxResultsUSA results = null;

            var instancePath = "xunit_tests/tax-stamper/TaxRatesServiceUSA";
            var name         = "TaxRatesServiceUSA";
            var logger       = GetLogger(instancePath, name);

            var service = new FindTaxRatesUSAImpl(
                logger
                , GetUseTaxRatesRepositoryUSA(logger, name + "_UseTax", instancePath)
                , GetSalesTaxRatesRepositoryUSA(logger, name + "_SalesTax", instancePath)
                );

            // find record - Sales
            search = new TaxSearchUSA()
            {
                Zipcode    = "68136"
                , ZipPlus4 = "2121"
                , OnDate   = DateTime.Now
            };
            results = service.FindSalesTaxRates(search);

            Assert.Equal(0.08, results.TaxRateState);
            Assert.Equal(0.06, results.TaxRateCounty);
            Assert.Equal(0.04, results.TaxRateCity);
            Assert.Equal(0.03, results.TaxRateLocal1);
            Assert.Equal(0.02, results.TaxRateLocal2);

            // find record - Use
            search = new TaxSearchUSA()
            {
                Zipcode    = "68136"
                , ZipPlus4 = "2121"
                , OnDate   = DateTime.Now
            };
            results = service.FindUseTaxRates(search);

            Assert.Equal(0.07, results.TaxRateState);
            Assert.Equal(0.05, results.TaxRateCounty);
            Assert.Equal(0.03, results.TaxRateCity);
            Assert.Equal(0.02, results.TaxRateLocal1);
            Assert.Equal(0.01, results.TaxRateLocal2);

            // bad data - Zipcode
            search = new TaxSearchUSA()
            {
                Zipcode    = "ABCDE"
                , ZipPlus4 = "1234"
                , OnDate   = DateTime.Now
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - ZipPlus4
            search = new TaxSearchUSA()
            {
                Zipcode    = "68136"
                , ZipPlus4 = "ABCD"
                , OnDate   = DateTime.Now
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - OnDate is ancient
            search = new TaxSearchUSA()
            {
                Zipcode    = "68136"
                , ZipPlus4 = "1234"
                , OnDate   = new DateTime(1800, 1, 1)
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - OnDate too future
            search = new TaxSearchUSA()
            {
                Zipcode    = "68136"
                , ZipPlus4 = "1234"
                , OnDate   = new DateTime(2100, 1, 1)
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // no record
            search = new TaxSearchUSA()
            {
                Zipcode    = "88888"
                , ZipPlus4 = "1234"
                , OnDate   = DateTime.Now
            };
            Assert.Throws <KeyNotFoundException>(() => results = service.FindSalesTaxRates(search));
        }
Exemplo n.º 3
0
        public TaxResultsUSA FindSalesTaxRates(TaxSearchUSA searchBy)
        {
            _logger.Verbose($"{this.GetType().Name} IN FindSalesTaxRates");

            return(FindTaxRates(searchBy, _salesTaxRatesRepositoryUSA));
        }