Exemplo n.º 1
0
        public void TestCalculateTax(float expectedFullPrice, float price, RegionTax regionTax)
        {
            TaxResponse response = _taxCalculatorService.CalculateTax(price, regionTax);

            Assert.AreEqual(expectedFullPrice, response.FullPrice);
            Assert.AreEqual(price, response.OriginalPrice);
            Assert.AreEqual(regionTax.EstimatedCombinedRate, response.TaxRate);
        }
Exemplo n.º 2
0
        public void TestConstructor()
        {
            string jsonRegionTax = "[{" +
                                   "\"state\": \"NC\"," +
                                   "\"zipCode\": \"12345\"," +
                                   "\"taxRegionName\": \"raleigh\"," +
                                   "\"stateRate\": 0.0475," +
                                   "\"estimatedCombinedRate\": 0.0675," +
                                   "\"estimatedCountyRate\": 0.02," +
                                   "\"estimatedCityRate\": 0," +
                                   "\"estimatedSpecialRate\": 0," +
                                   "\"riskLevel\": 6" +
                                   "},{" +
                                   "\"state\": \"NC\"," +
                                   "\"zipCode\": \"54321\"," +
                                   "\"taxRegionName\": \"charlotte\"," +
                                   "\"stateRate\": 0.0475," +
                                   "\"estimatedCombinedRate\": 0.07," +
                                   "\"estimatedCountyRate\": 0.0225," +
                                   "\"estimatedCityRate\": 0," +
                                   "\"estimatedSpecialRate\": 0," +
                                   "\"riskLevel\": 2" +
                                   "}]";

            TaxRegionsRepository taxRegionsRepository = new TaxRegionsRepository(jsonRegionTax);

            RegionTax raleigh = new RegionTax
            {
                State                 = "NC",
                ZipCode               = "12345",
                TaxRegionName         = "raleigh",
                StateRate             = 0.0475f,
                EstimatedCombinedRate = 0.0675f,
                EstimatedCountyRate   = 0.02f,
                EstimatedCityRate     = 0f,
                EstimatedSpecialRate  = 0f,
                RiskLevel             = 6
            };
            RegionTax charlotte = new RegionTax
            {
                State                 = "NC",
                ZipCode               = "54321",
                TaxRegionName         = "charlotte",
                StateRate             = 0.0475f,
                EstimatedCombinedRate = 0.07f,
                EstimatedCountyRate   = 0.0225f,
                EstimatedCityRate     = 0f,
                EstimatedSpecialRate  = 0f,
                RiskLevel             = 2
            };
            List <RegionTax> regionTaxes = new List <RegionTax> {
                raleigh, charlotte
            };

            CollectionAssert.AreEqual(regionTaxes, taxRegionsRepository.TaxRegions);
        }
Exemplo n.º 3
0
        public void TestGet_Successful()
        {
            string zipCode = "12345";
            string price   = "4.75";

            RegionTax regionTax = new RegionTax()
            {
                State = "NC", ZipCode = "12345", EstimatedCombinedRate = .05f
            };
            TaxResponse taxResponse = new TaxResponse(4.75f, 4.99f, .05f);

            _mockTaxInputUtility.Setup(utility => utility.ValidateZipCode(It.Is <string>(value => value == zipCode)))
            .Returns(zipCode);
            _mockTaxInputUtility.Setup(utility => utility.ValidatePrice(It.Is <string>(value => value == price)))
            .Returns(4.75f);

            _mockTaxService.Setup(service => service.GetByZipCode(zipCode)).Returns(regionTax);

            _mockTaxCalculatorService.Setup(service =>
                                            service.CalculateTax(It.Is <float>(f => f == 4.75f), It.Is <RegionTax>(tax => tax == regionTax)))
            .Returns(taxResponse);

            Assert.AreEqual(taxResponse, _taxController.Get(price, zipCode).Value);
        }
        public TaxResponse CalculateTax(float price, RegionTax regionTax)
        {
            float fullPrice = (price * regionTax.EstimatedCombinedRate) + price;

            return(new TaxResponse(price, fullPrice, regionTax.EstimatedCombinedRate));
        }