示例#1
0
        public async void GetTaxForOrder_Expect_Sucsess()
        {
            // Setup
            var mockResponse = new GetOrderSalesTaxResponse()
            {
                SalesTax = new SalesTax
                {
                    amount_to_collect  = 12.90,
                    Order_total_amount = 124.88,
                    jurisdictions      = new Jurisdictions
                    {
                        city    = "Saint Pete",
                        country = "US"
                    }
                }
            };

            var fakeRequest = new GetOrderSalesTaxRequest {
            };

            _apiClient.Setup(x => x.PostAsync <GetOrderSalesTaxResponse>(It.IsAny <string>(), It.IsAny <object>()))
            .Returns(Task.FromResult(mockResponse)).Verifiable();

            // Act
            var actualResponse = await _taxRepository.GetOrderSalesTax(fakeRequest) as GetOrderSalesTaxResponse;

            // Assert
            Assert.NotNull(actualResponse);
            Assert.NotNull(actualResponse.SalesTax);
            Assert.Equal(12.90, actualResponse.SalesTax.amount_to_collect);
            Assert.Equal(124.88, actualResponse.SalesTax.Order_total_amount);
            Assert.NotNull(actualResponse.SalesTax.jurisdictions);
            Assert.Equal("Saint Pete", actualResponse.SalesTax.jurisdictions.city);
        }
        public async void GetOrderSalesTax_ValidInput_Expect_Success(int amount, string fromCountry, string toCountry)
        {
            // Setup
            var mockResponse = new GetOrderSalesTaxResponse()
            {
                SalesTax = new SalesTax
                {
                    amount_to_collect  = 12.90,
                    Order_total_amount = 124.88,
                    breakdown          = new Breakdown
                    {
                        city_taxable_amount = 78,
                        city_tax_rate       = 7
                    },
                    jurisdictions = new Jurisdictions
                    {
                        city    = "Saint Pete",
                        country = "US"
                    }
                }
            };
            var fakeRequest = new GetOrderSalesTaxRequestModel
            {
                Amount       = amount,
                From_country = fromCountry,
                To_country   = toCountry
            };

            _taxProvider.Setup(x => x.GetOrderSalesTax(It.IsAny <GetOrderSalesTaxRequestModel>()))
            .Returns(Task.FromResult(mockResponse)).Verifiable();

            // Act
            var actualResponse = await _taxController.GetOrderSalesTax(fakeRequest) as OkObjectResult;

            var data = actualResponse.Value as GetOrderSalesTaxResponse;

            // Assert
            Assert.NotNull(actualResponse);
            Assert.NotNull(data);
            Assert.NotNull(data.SalesTax);
            Assert.Equal(12.90, data.SalesTax.amount_to_collect);
            Assert.Equal(124.88, data.SalesTax.Order_total_amount);
            Assert.NotNull(data.SalesTax.breakdown);
            Assert.Equal(78, data.SalesTax.breakdown.city_taxable_amount);
            Assert.NotNull(data.SalesTax.jurisdictions);
            Assert.Equal("Saint Pete", data.SalesTax.jurisdictions.city);
        }