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); }
protected ActionResult DisplayDetails(RoleDTO item) { var vm = GetViewModelFromTempData<RoleViewModel>(); if (vm == null) { return RedirectToReferrer(); } vm.DisplayName = Strings.RoleDetailView_Title; vm.SelectedItem = item; var vmUser = GetViewModelFromTempData<UserViewModel>(typeof(UserController).FullName); vm.Roles = vm.Roles ?? Service .GetAllRoles() .Where(r1 => !vmUser.Roles.Items.Exists(r2 => r2.RoleName == r1.RoleName)) .ToList(); // Finish Action StoreViewModelToTempData(vm); TempData.Keep(); return View(vm); }
private static Role DtoToRole(RoleDTO dto) { Role role = new Role() { RoleId = dto.Id, RoleName = dto.RoleName, Version = dto.Version }; ValidationHelper.Validate(role); return role; }
public static RoleDTO RoleToDTO(Role r) { RoleDTO dto = new RoleDTO() { Id = r.RoleId, RoleName = r.RoleName, Version = r.Version }; return dto; }
// GET: Role/Create public ActionResult Create() { RoleDTO item = new RoleDTO(); return DisplayDetails(item); }
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()); }
public void TestRoleDetailViewModel() { RoleDTO roleDTO = new RoleDTO() {Id = 1, RoleName = "FakeName", Version = 0}; RoleDetailViewModel viewModel = new RoleDetailViewModel(roleDTO, false); Assert.AreEqual(roleDTO, viewModel.Model); Assert.AreEqual(Strings.RoleDetailViewModel_DisplayName, viewModel.DisplayName); }