Пример #1
0
        public void CalculateTax_SantaMonicaZipTest()
        {
            TaxJar      taxJar      = new TaxJar();
            TaxResponse taxResponse = new TaxResponse();

            Tax tax = new Tax();

            tax.FromCountry = "US";
            tax.FromZip     = "07001";
            tax.FromState   = "NJ";
            tax.ToCountry   = "US";
            tax.ToZip       = "07446";
            tax.ToState     = "NJ";
            tax.Amount      = 16.5m;
            tax.Shipping    = 1.5m;

            TaxLineItem lineItem = new TaxLineItem();

            lineItem.Quantity       = 1;
            lineItem.UnitPrice      = 15.0m;
            lineItem.ProductTaxCode = "31000";

            tax.LineItems.Add(lineItem);

            var taxService = new TaxService.TaxService();

            Task.Run(async() =>
            {
                taxResponse.Tax = await taxService.CalculateTax(taxJar, tax);
            });

            Assert.IsTrue(taxResponse.OrderTotalAmount == 16.5m);
            Assert.IsTrue(taxResponse.Shipping == 1.5m);
        }
        public void GetRate_EmptyZipTest()
        {
            TaxJar       taxJar       = new TaxJar();
            RateResponse rateResponse = new RateResponse();

            string zip = "";

            var taxService = new TaxService.TaxService();

            Task.Run(async() =>
            {
                rateResponse.Rate = await taxService.GetRate(taxJar, zip);
            });

            Assert.IsNull(rateResponse.Rate);
        }
Пример #3
0
        public void GetRate_SantaMonicaZipTest()
        {
            TaxJar       taxJar       = new TaxJar();
            RateResponse rateResponse = new RateResponse();

            //zip of city of Santa Monica
            string zip = "90404";

            var taxService = new TaxService.TaxService();

            Task.Run(async() =>
            {
                rateResponse.Rate = await taxService.GetRate(taxJar, zip);
            });

            Assert.IsTrue(rateResponse.Rate.City.Equals("SANTA MONICA"));
        }
        public void CalculateTax_EmptyToCountryTaxInfoTest()
        {
            TaxJar      taxJar      = new TaxJar();
            TaxResponse taxResponse = new TaxResponse();

            Tax tax = new Tax();

            tax.ToCountry = "";

            var taxService = new TaxService.TaxService();

            Task.Run(async() =>
            {
                taxResponse.Tax = await taxService.CalculateTax(taxJar, tax);
            });

            Assert.IsNull(taxResponse.Tax);
        }
Пример #5
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Welcome! This is a console for some Tax Calculation Testing.");
            Console.WriteLine("");

            // The API key can be stored in a Azure key vault for security purpose
            // Hard coded for now
            string strTaxjarApiKey = "5da2f821eee4035db4771edab942a4cc";

            // test data / parameter preparation
            string strZip  = "30024";
            var    address = new Address {
                Country = "US", City = "Suwanee", Street = "3620 Peachtree Pkwy"
            };

            var order = new Order {
                FromCountry = "US",
                FromZip     = "92093",
                FromState   = "CA",
                FromCity    = "La Jolla",
                FromStreet  = "9500 Gilman Drive",
                ToCountry   = "US",
                ToZip       = "90002",
                ToState     = "CA",
                ToCity      = "Los Angeles",
                ToStreet    = "1335 E 103rd St",
                Amount      = 15F,
                Shipping    = 1.5F
            };

            string  strRate;
            TaxRate taxRate;
            string  strTax;

            // Testing TaxjarClient class
            Console.WriteLine("Testing TaxjarClient class ... \n");

            var taxjarClient = new TaxjarClient.TaxjarClient(strTaxjarApiKey);

            strRate = await taxjarClient.GetTaxRateAsync(strZip, address);

            Console.WriteLine(strRate);
            Console.WriteLine("\n");

            strTax = await taxjarClient.TaxForOrderAsync(order);

            Console.WriteLine(strTax);
            Console.WriteLine("\n\n");

            // Testing TaxService class
            Console.WriteLine("Testing TaxService class ... \n");

            var taxService = new TaxService.TaxService(taxjarClient);

            strRate = await taxService.GetTaxRateAsync(strZip);

            Console.WriteLine(strRate);
            Console.WriteLine("\n");

            strRate = await taxService.GetTaxRateAsync(strZip, address);

            Console.WriteLine(strRate);
            Console.WriteLine("\n");

            taxRate = await taxService.GetTaxRateObjectAsync("30301");

            Console.WriteLine(taxRate.ToString());
            Console.WriteLine("\n");

            taxRate = await taxService.GetTaxRateObjectAsync(strZip, address);

            Console.WriteLine(taxRate.ToString());
            Console.WriteLine("\n");

            strTax = await taxService.TaxForOrderAsync(order);

            Console.WriteLine(strTax);
        }