public void EditUserSearchRole() { var controller = GetController(); var list = new List<User>(); var search = new UserSearch { SearchText = "blah", SearchType = UserSearch.UserSearchType.Role }; _userService.Setup(u => u.SearchByRole("blah")).Returns(list); var result = controller.EditUserSearch(search); _userService.Verify(u => u.SearchByRole("blah"), Times.Once()); Assert.AreSame(list, result.ViewData.Model); }
public ViewResult EditUserSearch(UserSearch userSearch) { ViewBag.SearchText = userSearch.SearchText; ViewBag.UserSearchType = userSearch.SearchType; switch(userSearch.SearchType) { case UserSearch.UserSearchType.Email: return View(_userService.SearchByEmail(userSearch.SearchText)); case UserSearch.UserSearchType.Name: return View(_userService.SearchByName(userSearch.SearchText)); case UserSearch.UserSearchType.Role: return View(_userService.SearchByRole(userSearch.SearchText)); default: throw new ArgumentOutOfRangeException("userSearch"); } }
public void EditUserSearchPersistsValues() { var controller = GetController(); var search = new UserSearch {SearchText = "blah", SearchType = UserSearch.UserSearchType.Name}; var result = controller.EditUserSearch(search); Assert.AreEqual("blah", result.ViewData["SearchText"]); Assert.AreEqual("Name", result.ViewData["UserSearchType"].ToString()); }