public ActionResult Costs(Benefits benefits) { List <string> dependents = new List <string>(); if (string.IsNullOrEmpty(benefits.EmployeeName)) { benefits.Message = "Please enter Employee Name"; return(View("Benefits", benefits)); } if (string.IsNullOrEmpty(benefits.Dependents) == false) { string[] separators = { ",", ".", "!", "?", ";", ":", " " }; dependents = benefits.Dependents.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList(); } decimal cost = BenefitCalculator.CalculateCost(benefits.EmployeeName, dependents); decimal grossPay = BenefitCalculator.CalculateGrossPay(); decimal netPay = grossPay - cost; benefits.GrossPayMessage = $"Gross Pay: ${grossPay}"; benefits.CostMessage = $"Cost of Benefits: ${ cost}"; benefits.NetPayMessage = $"Net Pay:${netPay}"; return(View("Benefits", benefits)); }
public async Task ValidateInput_BadRequest_InvalidType_ReturnsFalse() { //Arrange BenefitCalculator calculator = new BenefitCalculator(); List <BeneficiaryRequestModel> testRequest = new List <BeneficiaryRequestModel> { new BeneficiaryRequestModel { Name = "Name1", Type = BenefitsData.Employee }, new BeneficiaryRequestModel { Name = "name2", Type = "badType" } }; //Act bool result = await calculator.ValidateRequest(testRequest); //Assert Assert.IsFalse(result, "Expected validation to fail as input contained an invalid type."); }
public void TestCalculateCostAjayOnly() { decimal cost = BenefitCalculator.CalculateCost("Ajay", new List <string>() { }); Assert.IsTrue(cost == 900); }
public void TestCalculateCostEmplooyeeOnly() { decimal cost = BenefitCalculator.CalculateCost("Haresh", new List <string>() { }); Assert.IsTrue(cost == 1000); }
public void TestCalculateCost() { decimal cost = BenefitCalculator.CalculateCost("Haresh", new List <string>() { "Nikita", "Aditya", "Alisha" }); Assert.IsTrue(cost == 2400); }
public void Setup() { var nameDiscount = new NameDiscount(); calculator = new BenefitCalculator(new List <IDiscount>() { nameDiscount }); }
public Decimal GetDependentCost(Int32 id) { IPayrollRepository repo = GetRepository(); Decimal cost = 0; Dependent dependent = repo.GetDependentById(id); if (dependent != null) { BenefitCalculator calc = new BenefitCalculator(dependent.Employee.BenefitPlan, dependent.Employee.PayCycle, new NameDiscount()); cost = calc.CalculatePayPeriodCost(dependent); } return(cost); }
public Decimal GetEmployeeCost(Int32 id) { IPayrollRepository repo = GetRepository(); Decimal cost = 0; Employee employee = repo.GetEmployeeById(id); if (employee != null) { BenefitCalculator calc = new BenefitCalculator(employee.BenefitPlan, employee.PayCycle, new NameDiscount()); cost = calc.CalculatePayPeriodCost(employee); } return(cost); }
public async Task ValidateInput_ValidRequest_ReturnsTrue() { //Arrange BenefitCalculator calculator = new BenefitCalculator(); List <BeneficiaryRequestModel> testRequest = new List <BeneficiaryRequestModel> { new BeneficiaryRequestModel { Name = "name1", Type = BenefitsData.Employee }, new BeneficiaryRequestModel { Name = "name2", Type = BenefitsData.Dependent } }; //Act bool result = await calculator.ValidateRequest(testRequest); //Assert Assert.IsTrue(result, "Expected validation to pass as inputs were valid"); }
public async Task CalculateBenefits_GivenInput_ReturnsExpectedCosts() { //Arrange string name1 = "Name1"; string name2 = "Name2"; decimal discount = 0.5M; int payPeriods = 10; decimal employeeYearCost = 400M; decimal dependentYearCost = 200M; decimal employeeDiscountYearCost = (1 - discount) * employeeYearCost; decimal dependentDiscountYearCost = (1 - discount) * dependentYearCost; List <BeneficiaryRequestModel> testRequest = new List <BeneficiaryRequestModel> { new BeneficiaryRequestModel { Name = name1, Type = BenefitsData.Employee }, new BeneficiaryRequestModel { Name = name2, Type = BenefitsData.Dependent } }; BenefitCalculator calculator = new BenefitCalculator(); IDiscountHandler fakeDiscountHandler = A.Fake <IDiscountHandler>(); IDataAccessor fakeDataAccess = A.Fake <IDataAccessor>(); calculator.DiscountHandler = fakeDiscountHandler; calculator.DataAccess = fakeDataAccess; A.CallTo(() => fakeDiscountHandler.EligibleForDiscount(A <string> .Ignored)).Returns(true); A.CallTo(() => fakeDataAccess.GetBenefitCostsAsync(BenefitsData.Employee)).Returns(Task.FromResult(employeeYearCost)); A.CallTo(() => fakeDataAccess.GetBenefitCostsAsync(BenefitsData.Dependent)).Returns(Task.FromResult(dependentYearCost)); A.CallTo(() => fakeDataAccess.GetDiscountAsync()).Returns(Task.FromResult(discount)); A.CallTo(() => fakeDataAccess.GetPayPeriodsAsync()).Returns(Task.FromResult(payPeriods)); //Act var response = await calculator.CalculateBenefits(testRequest); //Assert A.CallTo(() => fakeDiscountHandler.EligibleForDiscount(name1)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDiscountHandler.EligibleForDiscount(name2)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDataAccess.GetDiscountAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDataAccess.GetPayPeriodsAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDataAccess.GetBenefitCostsAsync(BenefitsData.Employee)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDataAccess.GetBenefitCostsAsync(BenefitsData.Dependent)).MustHaveHappenedOnceExactly(); BeneficiaryResponseModel expected1 = new BeneficiaryResponseModel { Name = name1, Type = BenefitsData.Employee, YearCost = employeeDiscountYearCost, PeriodCost = decimal.Round((employeeDiscountYearCost / payPeriods), 2) }; BeneficiaryResponseModel expected2 = new BeneficiaryResponseModel { Name = name2, Type = BenefitsData.Dependent, YearCost = dependentDiscountYearCost, PeriodCost = decimal.Round((dependentDiscountYearCost / payPeriods), 2) }; Assert.AreEqual(2, response.Count, "Expected the response to contain the same number of entries as input"); var bene1 = response.Where(b => { return(b.Name.Equals(expected1.Name) && b.Type.Equals(expected1.Type) && b.YearCost == expected1.YearCost && b.PeriodCost == expected1.PeriodCost); }); var bene2 = response.Where(b => { return(b.Name.Equals(expected2.Name) && b.Type.Equals(expected2.Type) && b.YearCost == expected2.YearCost && b.PeriodCost == expected2.PeriodCost); }); Assert.AreEqual(1, bene1.Count(), "Expected the response to contain expected1 model"); Assert.AreEqual(1, bene2.Count(), "Expected the response to contain expected2 model"); }
public void TestCalculateGrossPay() { decimal grossPay = BenefitCalculator.CalculateGrossPay(); Assert.IsTrue(grossPay == 52000); }