// GET: View public ActionResult Index() { EmployeeBenefitsService service = new EmployeeBenefitsService(new EmployeeBenefitsRepository()); List <EmployeesDependents> employeesDependents = service.GetAllEmployeesAndDependentsCost(); return(View(employeesDependents)); }
public ActionResult Save([ModelBinder(typeof(EmployeeBinder))] Employee employeeModel) { if (ModelState.IsValid) { //saving the employee/dependents EmployeeBenefitsService service = new EmployeeBenefitsService(new EmployeeBenefitsRepository()); TempData["IsSaved"] = service.Save(employeeModel); } return(RedirectToAction("Index")); }
public void CalculateBenefitsCostForEmployeeWithLetterA_ShouldReturn900() { Mock <Employee> mockEmployee = new Mock <Employee>(); mockEmployee.Object.Name = "Albert"; BenefitsSummary benefitsSummary = new EmployeeBenefitsService(new EmployeeBenefitsRepository()).CalculateBenefitsCost(mockEmployee.Object); Assert.AreEqual(benefitsSummary.EmployeeCost, 900.00m, "Employee Cost incorrect"); Assert.AreEqual(benefitsSummary.TotalCost, 900.00m, "Employee Total Cost incorrect"); Assert.AreEqual(Math.Round(benefitsSummary.CostPerPayCheck, 2), 34.62m, "Cost per check is incorrect"); }
public HttpResponseMessage Save([FromBody] Employee employee) { try { EmployeeBenefitsService service = new EmployeeBenefitsService(new EmployeeBenefitsRepository()); bool isSaved = service.Save(employee); return(Request.CreateResponse(HttpStatusCode.OK, new { isSaved })); } catch (Exception ex) { Log.LogMessage(TracingLevel.ERROR, ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error")); } }
public HttpResponseMessage CalculateBenefitsCost([FromBody] Employee employee) { try { EmployeeBenefitsService service = new EmployeeBenefitsService(new EmployeeBenefitsRepository()); BenefitsSummary summary = service.CalculateBenefitsCost(employee); return(Request.CreateResponse(HttpStatusCode.OK, new { summary })); } catch (Exception ex) { Log.LogMessage(TracingLevel.ERROR, ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error")); } }
public void CalculateBenefitsCostForEmployeeAndDependentsWithLetterA_ShouldReturnDependentCostOf450_And_TotalCostOf1450() { Mock <Employee> mockEmployee = new Mock <Employee>(); mockEmployee.Object.Name = "Khuong"; mockEmployee.Object.Dependents.Add(new Dependent() { Name = "Adele" }); BenefitsSummary benefitsSummary = new EmployeeBenefitsService(new EmployeeBenefitsRepository()).CalculateBenefitsCost(mockEmployee.Object); Assert.AreEqual(benefitsSummary.DependentsCost, 450.00m, "Dependent Cost incorrect"); Assert.AreEqual(benefitsSummary.TotalCost, 1450.00m, "Employee Total Cost incorrect"); Assert.AreEqual(Math.Round(benefitsSummary.CostPerPayCheck, 2), 55.77m, "Cost per check is incorrect"); }
public void SaveEmployeeBenefits_ShouldReturnBoolean() { Mock <Employee> mockEmployee = new Mock <Employee>(); mockEmployee.Object.Name = "Khuong"; mockEmployee.Object.Dependents.Add(new Dependent() { Name = "Kylie" }); mockEmployee.Object.Dependents.Add(new Dependent() { Name = "Evie" }); mockEmployee.Object.BenefitsSummary = new BenefitsSummary() { DependentsCost = 1000, EmployeeCost = 1000, TotalCost = 2000, TotalSalary = 52000 }; Data.Employee employeeData = new Data.Employee() { Name = mockEmployee.Object.Name }; foreach (var dependents in mockEmployee.Object.Dependents) { employeeData.Dependents.Add(new Data.Dependent() { Name = dependents.Name }); } employeeData.Benefits.Add(new Data.Benefit() { DependentCost = mockEmployee.Object.BenefitsSummary.DependentsCost, EmployeeCost = mockEmployee.Object.BenefitsSummary.EmployeeCost }); Mock <IEmployeeBenefitsRepository> mockRepository = new Mock <IEmployeeBenefitsRepository>(); mockRepository.Setup(r => r.SaveEmployeeBenefits(It.IsAny <Data.Employee>())).Returns((Data.Employee target) => { if (target.Name != "Khuong") { return(false); } if (target.Dependents.Count != 2) { return(false); } foreach (var benefit in target.Benefits) { if (benefit.DependentCost != 1000.00m) { return(false); } if (benefit.EmployeeCost != 1000.00m) { return(false); } } return(true); }); bool isSaved = new EmployeeBenefitsService(mockRepository.Object).Save(mockEmployee.Object); Assert.IsTrue(isSaved, "View Model not mapped to Data Model correctly"); }