public ActionResult Edit(int id) { var viewModel = new CreateEditClientBudgetViewModel(userManager.GetRoles(User.Identity.GetUserId())); var budget = budgetRepository.Where(c => c.Id == id).First(); viewModel.ClientName = budget.Client.Name; viewModel.Month = budget.Month.ToString("yyyy-MM"); viewModel.Value = Math.Round(budget.Value, 2); viewModel.BudgetId = id; viewModel.ClientId = budget.ClientId; viewModel.Comment = budget.Comment; return(View(viewModel)); }
public void EditGetReturnsCorrectData() { IRepository <Client> clientRepository = new LocalRepository <Client>(); IRepository <Budget> budgetRepository = new LocalRepository <Budget>(); var userManager = new Mock <IIdentityMembershipProvider>(); Budget budget1 = new Budget(); budget1.Id = 1; budget1.Value = 1000; budget1.Month = new DateTime(2014, 1, 1); budget1.ClientId = 1; budget1.Comment = "Comment"; budget1.Client = new Client { Name = "Client Name" }; budgetRepository.Add(budget1); Assert.AreEqual(1, budgetRepository.All().Count()); userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> { "mockRole" }); var controller = new BudgetController(clientRepository, budgetRepository, userManager.Object); var claim = new Claim("test", "AnyId"); ModelHelper.SetClaimAsCurrentUserForController(claim, controller); var expectedEditBudgetInRepository = new CreateEditClientBudgetViewModel { BudgetId = 1, ClientId = 1, Month = "2014-01", Value = 1000, Comment = "Comment", ClientName = "Client Name" }; var result = controller.Edit(1) as ViewResult; var resultModel = result.Model as CreateEditClientBudgetViewModel; Assert.AreEqual(expectedEditBudgetInRepository.BudgetId, resultModel.BudgetId); Assert.AreEqual(expectedEditBudgetInRepository.ClientId, resultModel.ClientId); Assert.AreEqual(expectedEditBudgetInRepository.Month, resultModel.Month); Assert.AreEqual(expectedEditBudgetInRepository.Value, resultModel.Value); Assert.AreEqual(expectedEditBudgetInRepository.Comment, resultModel.Comment); Assert.AreEqual(expectedEditBudgetInRepository.ClientName, resultModel.ClientName); }