コード例 #1
0
		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);
		}
コード例 #2
0
		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");
			}
		}
コード例 #3
0
		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());
		}