public void Test_GetPayslip_3() { var payslipController = new PaySlipController(new PaySlipService()); payslipController.Request = new HttpRequestMessage(); payslipController.Configuration = new HttpConfiguration(); var employee = new PaySlipInputModel() { FirstName = "Durgesh", LastName = "Pandey", AnualSalary = 10000, PaymentStartDate = (new DateTime(2018, 06, 30)).ToShortDateString(), SuperRate = 0 }; PaySlipModel paySlip; var response = (HttpResponseMessage)payslipController.GetPaySlip(employee); Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); Assert.IsTrue(response.TryGetContentValue <PaySlipModel>(out paySlip)); Assert.IsNotNull(paySlip); Assert.AreEqual(833, paySlip.GrossIncome); Assert.AreEqual(0, paySlip.IncomeTax); Assert.AreEqual(833, paySlip.NetIncome); Assert.AreEqual(0, paySlip.SuperAmount); }
public PaySlipModel GetPaySlip(PaySlipInputModel paySlipInputModel) { decimal tax = 0; if (paySlipInputModel.AnualSalary < 0) { throw new Exception("Salary should be greater than 0"); } paySlipInputModel.AnualSalary = Math.Round(paySlipInputModel.AnualSalary, 1); if (paySlipInputModel.AnualSalary > 0 && paySlipInputModel.AnualSalary <= 18200) { tax = 0; } if (paySlipInputModel.AnualSalary > 18200) { decimal taxableAmount; taxableAmount = paySlipInputModel.AnualSalary <= 37000? paySlipInputModel.AnualSalary - 18200: (37000 - 18200); tax += taxableAmount * (decimal)(19.0 / 100); if (paySlipInputModel.AnualSalary > 37000) { taxableAmount = paySlipInputModel.AnualSalary <= 87000 ? paySlipInputModel.AnualSalary - 37000 : (87000 - 37000); tax += taxableAmount * (decimal)(32.5 / 100); if (paySlipInputModel.AnualSalary > 87000) { taxableAmount = paySlipInputModel.AnualSalary <= 180000 ? paySlipInputModel.AnualSalary - 87000 : (180000 - 87000); tax += taxableAmount * (decimal)(37.0 / 100); if (paySlipInputModel.AnualSalary > 180000) { taxableAmount = paySlipInputModel.AnualSalary - 180000; tax += taxableAmount * (decimal)(45.0 / 100); } } } } return(new PaySlipModel { GrossIncome = Math.Round(paySlipInputModel.AnualSalary / 12, 0) , IncomeTax = Math.Round(tax / 12, 0) , NetIncome = Math.Round(paySlipInputModel.AnualSalary / 12, 0) - Math.Round(tax / 12, 0) , SuperAmount = Math.Round((paySlipInputModel.AnualSalary / 12) * (paySlipInputModel.SuperRate / 100), 0) , Name = paySlipInputModel.FirstName + " " + paySlipInputModel.LastName , PayPeriod = paySlipInputModel.PaymentStartDate }); }
public void NegativeTest_GetPayslip2() { var payslipController = new PaySlipController(new PaySlipService()); payslipController.Request = new HttpRequestMessage(); payslipController.Configuration = new HttpConfiguration(); var employee = new PaySlipInputModel() { FirstName = "Durgesh", LastName = "Pandey", AnualSalary = -200, PaymentStartDate = (new DateTime(2018, 06, 30)).ToShortDateString(), SuperRate = -3 }; var response = (payslipController.GetPaySlip(employee)); // Assert Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError); }
public HttpResponseMessage GetPaySlip(PaySlipInputModel paySlipInputModel) { try { if (paySlipInputModel == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data provided in the request is not valid.")); } if (ModelState.IsValid) { var result = _paySlipService.GetPaySlip(paySlipInputModel); return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data provided in the request is not valid.")); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }