public ActionResult Index() { var userName = GetUserName(); List <ProjectService> projectServices = _repository.GetProjectServicesForUserName(userName); if (projectServices == null) { return(View()); } List <ProjectServiceViewModel> projectServiceVMList = new List <ProjectServiceViewModel>(projectServices.Count); foreach (ProjectService ps in projectServices) { ProjectServiceViewModel psvm = new ProjectServiceViewModel(); psvm.ProjectId = ps.ProjectId; psvm.ServiceID = ps.ServiceID; psvm.Project = ps.Project; psvm.Service = ps.Service; psvm.HoursWorked = ps.HoursWorked; psvm.TotalPrice = ps.HoursWorked * psvm.Service.Price; projectServiceVMList.Add(psvm); } return(View(projectServiceVMList)); }
public void TestIndexViewFindsCorrectClientsOneClient() { var repository = new Mock <IProjectServiceRepository>(); ProjectService projectService = new ProjectService(); projectService.ProjectId = 1; projectService.Service = new Service() { Price = 20, ServiceiD = 1, ServiceName = "Unit test service name" }; repository.Setup(m => m.GetProjectServicesForUserName(TEST_USER_NAME)).Returns(() => new List <ProjectService> { projectService }); var controller = ProjectServicesController.CreateProjectServiceControllerAs(TEST_USER_NAME, repository.Object); ViewResult result = controller.Index() as ViewResult; List <ProjectServiceViewModel> results = result.Model as List <ProjectServiceViewModel>; ProjectServiceViewModel psvm = new ProjectServiceViewModel(); psvm.ProjectId = 1; psvm.Service = new Service() { Price = 20, ServiceiD = 1, ServiceName = "Unit test service name" }; Assert.AreEqual(psvm.ProjectId, results[0].ProjectId); Assert.AreEqual(psvm.Service.Price, results[0].Service.Price); Assert.AreEqual(psvm.Service.ServiceiD, results[0].Service.ServiceiD); Assert.AreEqual(psvm.Service.ServiceName, results[0].Service.ServiceName); }