コード例 #1
0
 public UserEditViewModel Display(UserEditViewModel userEditViewModel)
 {
     User user = _userRepository.GetUser(userEditViewModel.UserId);
     return new UserEditViewModel(user)
                {
                    Message = userEditViewModel.IsAjaxRequest() ? "Json Result" : "View Result"
                };
 }
コード例 #2
0
            public void Should_map_UserAddEditViewModel_to_User_with_DateOfBirth_set_to_null()
            {
                _userEditModel = new UserEditViewModel(_user);

                User actualUser = _mapper.MapFrom(_userEditModel);
                Assert.AreEqual(_user.UserId, actualUser.UserId);
                Assert.AreEqual(_user.LastName, actualUser.LastName);
                Assert.AreEqual(_user.FirstName, actualUser.FirstName);
                Assert.IsNull(actualUser.DateOfBirth);
            }
コード例 #3
0
            public void Should_map_UserAddEditViewModel_to_User()
            {
                _user.DateOfBirth = Convert.ToDateTime("12/12/1990");
                _userEditModel = new UserEditViewModel(_user);

                User actualUser = _mapper.MapFrom(_userEditModel);
                Assert.AreEqual(_user.UserId, actualUser.UserId);
                Assert.AreEqual(_user.LastName, actualUser.LastName);
                Assert.AreEqual(_user.FirstName, actualUser.FirstName);
                Assert.AreEqual(_user.DateOfBirth, actualUser.DateOfBirth);
            }
コード例 #4
0
 public UserListViewModel Delete(UserEditViewModel userEditViewModel)
 {
     User user = _mapper.MapFrom(userEditViewModel);
     string message;
     try
     {
         _userRepository.Delete(user);
         message = String.Format("User {0} successfully deleted", user.UserId);
     }
     catch (ArgumentException exception)
     {
         message = String.Format("User {0} could not be deleted: {1}", user.UserId, exception.Message);
     }
     UserListViewModel usersListViewModel = GetUsers();
     usersListViewModel.Message = message;
     return usersListViewModel;
 }
コード例 #5
0
            public void SetUp()
            {
                _mocker = new RhinoAutoMocker<UserController>();
                _userRepository = _mocker.Get<IUserRepository>();
                _userMapper = _mocker.Get<IMapper<UserEditViewModel, User>>();
                _userController = _mocker.ClassUnderTest;

                const string userId = "Test";
                _userEditModel = new UserEditViewModel
                                     {
                                         UserId = userId
                                     };
                _user = new User
                            {
                                UserId = userId
                            };
            }
コード例 #6
0
 public UserIndexViewModel Cancel(UserEditViewModel userEditViewModel)
 {
     _resultOverride.RedirectTo(_urlResolver.UrlFor <UserController>());
     return(new UserIndexViewModel());
 }
コード例 #7
0
        public UserEditViewModel Edit(UserEditViewModel userEditViewModel)
        {
            User user = _userRepository.GetUser(userEditViewModel.UserId);

            return(new UserEditViewModel(user));
        }
コード例 #8
0
 public UserEditViewModel New(UserEditViewModel userEditViewModel)
 {
     return(new UserEditViewModel());
 }
コード例 #9
0
 public UserEditViewModel Save(UserEditViewModel userEditViewModel)
 {
     if (String.IsNullOrEmpty(userEditViewModel.UserId))
     {
         userEditViewModel.Message = String.Format("UserId cannot be blank");
         return userEditViewModel;
     }
     User user = _mapper.MapFrom(userEditViewModel);
     try
     {
         _userRepository.Save(user);
         userEditViewModel.Message = "User saved successfully";
     }
     catch (Exception exception)
     {
         userEditViewModel.Message = String.Format("User could not be saved: {0}", exception.Message);
     }
     return userEditViewModel;
 }
コード例 #10
0
 public UserEditViewModel New(UserEditViewModel userEditViewModel)
 {
     return new UserEditViewModel();
 }
コード例 #11
0
 public UserEditViewModel Edit(UserEditViewModel userEditViewModel)
 {
     User user = _userRepository.GetUser(userEditViewModel.UserId);
     return new UserEditViewModel(user);
 }
コード例 #12
0
 public UserIndexViewModel Cancel(UserEditViewModel userEditViewModel)
 {
     _resultOverride.RedirectTo(_urlResolver.UrlFor<UserController>());
     return new UserIndexViewModel();
 }
コード例 #13
0
 public void SetUp()
 {
     _mocker = new RhinoAutoMocker<UserController>();
     _userController = _mocker.ClassUnderTest;
     _userEditModel = new UserEditViewModel();
 }
コード例 #14
0
            public void Should_display_error_message_if_UserId_is_blank()
            {
                _userEditModel = new UserEditViewModel();
                _userRepository.Expect(x => x.Save(null)).IgnoreArguments();

                UserEditViewModel userDisplayModel = _userController.Save(_userEditModel);

                Assert.IsNotNull(userDisplayModel);
                Assert.AreEqual("UserId cannot be blank", userDisplayModel.Message);
            }
コード例 #15
0
            public void SetUp()
            {
                _mocker = new RhinoAutoMocker<UserController>();
                _userRepository = _mocker.Get<IUserRepository>();
                _userController = _mocker.ClassUnderTest;

                _userEditModel = new UserEditViewModel
                                     {
                                         UserId = "Id"
                                     };
            }
コード例 #16
0
 public void SetUp()
 {
     _mocker = new RhinoAutoMocker<UserController>();
     _userRepository = _mocker.Get<IUserRepository>();
     _userController = _mocker.ClassUnderTest;
     _user = new User
                 {
                     UserId = "Id",
                     LastName = "LName",
                     FirstName = "FName"
                 };
     _userEditModel = new UserEditViewModel();
 }