public static UserDTO UserToDTO(User user)
        {
            UserDTO dto = new UserDTO()
                              {
                                  Id = user.UserId,
                                  UserName = user.UserName,
                                  Password = user.Password,
                                  Version = user.Version,
                                  CustomerId = (user.Customer == null) ? 0 : user.Customer.CustomerId,
                                  CustomerName = (user.Customer == null) ? string.Empty : user.Customer.ToString(),
                                  Roles = RolesToDTOs(user.Roles)
                              };

            return dto;
        }
 public static User DtoToUser(UserDTO dto)
 {
     User user = new User()
                     {
                         UserId = dto.Id,
                         UserName = dto.UserName,
                         Version = dto.Version,
                         Password = dto.Password,
                         Customer = (dto.CustomerId > 0) ? new Customer() {CustomerId = dto.CustomerId} : null
                     };
     ValidationHelper.Validate(user);
     return user;
 }
 public static IEnumerable<ChangeItem> GetChangeItems(UserDTO dto)
 {
     IEnumerable<ChangeItem> changeItems = from c in dto.Changes
                                           select
                                               new ChangeItem(c.ChangeType,
                                                              DtoToRole((RoleDTO) c.Object));
     return changeItems;
 }
 public void TestStoreUser()
 {
     UserDTO user = new UserDTO();
     user.Id = 123;
     StoreUserResponse response = new StoreUserResponse();
     response.Id = user.Id;
     Expect.Once.On(service).Method("StoreUser").Will(Return.Value(response));
     serviceFacade.StoreUser(user);
 }
        public void TestDtoToUser()
        {
            RoleDTO roleDTO = new RoleDTO() { Id = 1, RoleName = "FakeName", Version = 0 };
            UserDTO dto = new UserDTO() { Id = 1, UserName = "******", Password = "******", Version = 1 };
            dto.Roles.Add(roleDTO);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, roleDTO.IsValid);

            User user = SecurityAdapter.DtoToUser(dto);
            Assert.AreEqual<int>(dto.Id, user.UserId);
            Assert.AreEqual<string>(dto.UserName, user.UserName);
            Assert.AreEqual<string>(dto.Password, user.Password);
            Assert.AreEqual(dto.Version, user.Version);
            Assert.AreEqual(true, user.IsValid);
        }
        public void TestGetChangeItems()
        {
            UserDTO userDTO = new UserDTO();
            userDTO.MarkChildForInsertion(new RoleDTO { Id = 1, RoleName = "FakeRoleName", Version = 0 });
            userDTO.MarkChildForUpdate(new RoleDTO { Id = 2, RoleName = "FakeRoleName", Version = 0 });
            userDTO.MarkChildForDeletion(new RoleDTO { Id = 3, RoleName = "FakeRoleName", Version = 0 });

            IEnumerable<ChangeItem> changeItems = SecurityAdapter.GetChangeItems(userDTO);
            Assert.AreEqual<int>(3, changeItems.Count());
        }
 public void StoreUser(UserDTO user)
 {
     try
     {
         StoreUserRequest request = new StoreUserRequest();
         request.User = user;
         StoreUserResponse response = Service.StoreUser(request);
         user.Id = response.Id;
     }
     catch (Exception ex)
     {
         if (ExceptionPolicy.HandleException(ex, "PL Policy")) throw;
     }
 }
        public void TestUserDetailModel()
        {
            RoleDTO roleDTO = new RoleDTO() {Id = 1, RoleName = "FakeName", Version = 0};
            UserDTO dto = new UserDTO() {Id = 1, UserName = "******", Password = "******", Version = 1};
            dto.Roles.Add(roleDTO);

            UserDetailViewModel userDetailViewModel = new UserDetailViewModel(dto, false);
            userDetailViewModel.Service = serviceFacade;

            Expect.Once.On(serviceFacade).Method("StoreUser").With(dto);
            userDetailViewModel.SaveCommand.Command.Execute(null);

            Assert.AreEqual(dto, userDetailViewModel.Model);
            Assert.AreEqual(Strings.UserDetailViewModel_DisplayName, userDetailViewModel.DisplayName);

            RoleViewModel roleViewModel = (RoleViewModel) userDetailViewModel.ListViewModel;
            Assert.AreEqual(roleDTO, roleViewModel.Items.FirstOrDefault());
        }