Exemplo n.º 1
0
        public TaxResultsCA FindTaxRates(TaxSearchCA searchBy, ITaxRatesRepositoryCA 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 fetchedRecord = repo.FetchByZipcode(searchBy.ForwardStationArea, searchBy.LocalDeliveryUnit, searchBy.OnDate);

            if (fetchedRecord == null)
            {
                var notFoundMsg = string.Format(
                    "TaxRates for {0} {1} were not found"
                    , searchBy.ForwardStationArea
                    , searchBy.LocalDeliveryUnit
                    );
                _logger.Error(notFoundMsg);
                throw new KeyNotFoundException(notFoundMsg);
            }

            var results = new TaxResultsCA()
            {
                TaxRateGST   = fetchedRecord.TaxRateGST
                , TaxRatePST = fetchedRecord.TaxRatePST
                , TaxRateHST = fetchedRecord.TaxRateHST
            };

            return(results);
        }
Exemplo n.º 2
0
        public void FindTaxRatesCAService()
        {
            TaxSearchCA  search  = null;
            TaxResultsCA results = null;

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

            var service = new FindTaxRatesCAImpl(
                logger
                , GetUseTaxRatesRepositoryCA(logger, name + "_UseTax", instancePath)
                , GetSalesTaxRatesRepositoryCA(logger, name + "_SalesTax", instancePath)
                );

            // find record - Sales Tax
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , OnDate            = DateTime.Now
            };
            results = service.FindSalesTaxRates(search);

            Assert.Equal(0.08, results.TaxRateGST);
            Assert.Equal(0.06, results.TaxRatePST);
            Assert.Equal(0.04, results.TaxRateHST);

            // find record - Use Tax
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , OnDate            = DateTime.Now
            };
            results = service.FindUseTaxRates(search);

            Assert.Equal(0.07, results.TaxRateGST);
            Assert.Equal(0.05, results.TaxRatePST);
            Assert.Equal(0.03, results.TaxRateHST);

            // bad data - ForwardStationArea
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "AAA"
                , LocalDeliveryUnit = "5W6"
                , OnDate            = DateTime.Now
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - LocalDeliveryUnit
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "123"
                , OnDate            = DateTime.Now
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - OnDate is ancient
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , OnDate            = new DateTime(1800, 1, 1)
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // bad data - OnDate too future
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "K8N"
                , LocalDeliveryUnit = "5W6"
                , OnDate            = new DateTime(2100, 1, 1)
            };
            Assert.Throws <ArgumentException>(() => results = service.FindSalesTaxRates(search));

            // no record
            search = new TaxSearchCA()
            {
                ForwardStationArea  = "Z0Z"
                , LocalDeliveryUnit = "0Z0"
                , OnDate            = DateTime.Now
            };
            Assert.Throws <KeyNotFoundException>(() => results = service.FindSalesTaxRates(search));
        }