예제 #1
0
        public async Task <ActionResult <TaxCalculationResponseModel> > Calculate(TaxCalculationRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = await _calculatorManager.CalculateTax(new TaxCalculationRequest
            {
                AnnualIncome = model.AnnualIncome,
                PostalCode   = model.PostalCode,
                RequestedBy  = Guid.NewGuid()// to be set when authentication is available
            }).ConfigureAwait(false);

            if (result.HasErrors)
            {
                ModelState.AddErrors(result.GetErrorMessages());
                return(BadRequest(ModelState));
            }

            var responseModel = new TaxCalculationResponseModel
            {
                CalculationType = result.Response.CalculationType.GetDescription(),
                TaxAmount       = result.Response.TaxAmount,
                TaxYear         = result.Response.TaxYear
            };

            return(Ok(responseModel));
        }
예제 #2
0
        public async Task Skjs_ReturnsAcceptId(string sdyf, string acceptId)
        {
            var taxSetting   = XiaoAiGlobal.GlobalConfig.DefaultXiaoAiTaxSettings;
            var requestModel = new TaxCalculationRequestModel
            {
                NashuirenShibiehao = taxSetting.ShuiHao,
                AreaId             = taxSetting.Administrative,
                SuodeYuefen        = sdyf,
                DengjiXuhaoId      = taxSetting.DengjiXuhao,
                ShenbaoMima        = taxSetting.ShenbaoMima,
                Data = new IncomeData
                {
                    YukouYujiao = new YukouYujiao
                    {
                        ZhengchangGongziXinjinLiebiao = new List <PersonalNormalSalaryInfo>()
                        {
                            new PersonalNormalSalaryInfo
                            {
                                LicenseType         = Enums.LicenseType.居民身份证,
                                LicenseNumber       = "330421199712050024",
                                FullName            = "赵静文",
                                Shourue             = 10000,
                                JibenYanglaoBaoxian = 500,
                                JibenYiliaoBaoxian  = 200,
                                JianmianShuie       = 10
                            }
                        },
                        JianmianShixiangFubiaoLiebiao = new List <ReductionItemSchedule>()
                        {
                            new ReductionItemSchedule
                            {
                                LicenseType      = Enums.LicenseType.居民身份证,
                                LicenseNumber    = "330421199712050024",
                                FullName         = "赵静文",
                                JianmianFangshi  = 0,
                                SuodeXiangmu     = Enums.IncomeItem.正常工资薪金,
                                JianmianShixiang = "残疾、孤老、烈属减征个人所得税",
                                JianmianXingzhi  = "《中华人民共和国个人所得税法》 中华人民共和国主席令第48号第五条第一项",
                                JianmianJinE     = 10
                            }
                        }
                    }
                }
            };

            Response <BusinessAcceptedModel> result = await ApiFactory.CreateTaxClient().TaxCalculation(TokenSettings.AccessToken, requestModel, acceptId);

            Assert.NotNull(result);
            Assert.True(result.ExistsBusinessResponseContent);
            Assert.NotEmpty(result.BusinessResponseContent.AcceptId);
        }
예제 #3
0
        public async Task Calculate_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            //Arrange
            var expectedErrorMessage = "my errors";
            var errorKey             = "errorKey";

            _controller.ModelState.AddModelError(errorKey, expectedErrorMessage);
            TaxCalculationRequestModel model = new TaxCalculationRequestModel();

            //Act
            var result = await _controller.Calculate(model);

            //Assert
            Assert.IsInstanceOf <BadRequestResult>(result.Result);
        }
예제 #4
0
        public async Task Calculate_Should_Calculate()
        {
            //Arrange
            const decimal            annualIncome            = 250000;
            const string             postalCode              = "1234";
            const string             expectedTaxYear         = "Tax Year";
            const decimal            expectedTaxAmount       = 234.56M;
            const TaxCalculationType expectedCalculationType = TaxCalculationType.PROGRESSIVE_TAX;
            string expectedCalculationTypeDescription        = expectedCalculationType.GetDescription();

            TaxCalculationRequestModel model = new TaxCalculationRequestModel
            {
                AnnualIncome = annualIncome,
                PostalCode   = postalCode
            };

            TaxCalculationRequest actualManagerRequest = null;

            TaxCalculationResponse managerResponse = new TaxCalculationResponse
            {
                CalculationType = expectedCalculationType,
                TaxAmount       = expectedTaxAmount,
                TaxYear         = expectedTaxYear
            };

            _manager.Setup(r => r.CalculateTax(It.IsAny <TaxCalculationRequest>()))
            .Callback((TaxCalculationRequest r) => actualManagerRequest = r)
            .ReturnsAsync(() => new OperationResult <TaxCalculationResponse>(managerResponse));

            //Act
            var result = await _controller.Calculate(model);

            //Assert
            Assert.IsInstanceOf <OkObjectResult>(result.Result);
            TaxCalculationResponseModel
                responseMode = (TaxCalculationResponseModel)((OkObjectResult)result.Result).Value;

            Assert.AreEqual(expectedCalculationTypeDescription, responseMode.CalculationType);
            Assert.AreEqual(expectedTaxYear, responseMode.TaxYear);
            Assert.AreEqual(expectedTaxAmount, responseMode.TaxAmount);

            _manager.Verify(f => f.CalculateTax(It.IsAny <TaxCalculationRequest>()), Times.Once);
            Assert.AreEqual(annualIncome, actualManagerRequest.AnnualIncome);
            Assert.AreEqual(postalCode, actualManagerRequest.PostalCode);
        }
예제 #5
0
        public async Task Calculate_Should_Return_BadRequest_When_Manager_Returns_Errors()
        {
            //Arrange
            const decimal annualIncome         = 250000;
            const string  postalCode           = "1234";
            var           expectedErrorMessage = "my errors";
            var           errorKey             = "errorKey";

            TaxCalculationRequestModel model = new TaxCalculationRequestModel
            {
                AnnualIncome = annualIncome,
                PostalCode   = postalCode
            };

            TaxCalculationRequest actualManagerRequest = null;

            var managerResult = new OperationResult <TaxCalculationResponse>();

            managerResult.AddErrorMessage(errorKey, expectedErrorMessage);

            _manager.Setup(r => r.CalculateTax(It.IsAny <TaxCalculationRequest>()))
            .Callback((TaxCalculationRequest r) => actualManagerRequest = r)
            .ReturnsAsync(() => managerResult);

            //Act
            var result = await _controller.Calculate(model);

            //Assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result.Result);
            var
                responseModel = (SerializableError)((BadRequestObjectResult)result.Result).Value;

            Assert.AreEqual(expectedErrorMessage, ((string[])responseModel[errorKey])[0]);

            _manager.Verify(f => f.CalculateTax(It.IsAny <TaxCalculationRequest>()), Times.Once);
            Assert.AreEqual(annualIncome, actualManagerRequest.AnnualIncome);
            Assert.AreEqual(postalCode, actualManagerRequest.PostalCode);
        }
예제 #6
0
 /// <summary>
 /// 税款计算服务 <see cref="ITaxContract.TaxCalculation"/>
 /// </summary>
 /// <param name="bearerToken"></param>
 /// <param name="requestModel"></param>
 /// <param name="acceptId"></param>
 /// <param name="timeout"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public ITask <Response <BusinessAcceptedModel> > TaxCalculation(
     string bearerToken, TaxCalculationRequestModel requestModel, string acceptId,
     TimeSpan?timeout = null, CancellationToken cancellationToken = default)
 {
     return(TaxContract.TaxCalculation(bearerToken, requestModel.SuodeYuefen, acceptId, requestModel, timeout, cancellationToken));
 }