Beispiel #1
0
        public void DeleteUser(UserDTO userDTO)
        {
            ValidateUser(userDTO);

            User user = userRepository.GetByKey(userDTO.ID);
            userRepository.Remove(user);
            RepositoryContext.Commit();
        }
Beispiel #2
0
        public bool EnableUser(UserDTO userDTO)
        {
            ValidateUser(userDTO);

            User user = userRepository.GetByKey(userDTO.ID);
            user.Enable();
            userRepository.Update(user);
            RepositoryContext.Commit();
            return user.IsDisabled;
        }
Beispiel #3
0
        public UserDTO AddUser(UserDTO userDTO)
        {
            if (userDTO == null)
                throw new ArgumentNullException("用户不能为空");

            User user = Mapper.Map<UserDTO, User>(userDTO);
            userRepository.Add(user);
            RepositoryContext.Commit();
            return Mapper.Map<User, UserDTO>(user);
        }
Beispiel #4
0
        public void DeleteUsersTest()
        {
            Assert.IsTrue(userDTO1.ID == Guid.Empty);
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            Guid id = userDTO1.ID;
            userService.DeleteUser(userDTO1);
            UserDTO userByKey = userService.GetUserByKey(id);
            Assert.IsTrue(userByKey == null);
        }
Beispiel #5
0
        public void EnableUserTest()
        {
            Assert.IsTrue(userDTO1.ID == Guid.Empty);
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            userDTO1.IsDisabled = true;
            userService.EnableUser(userDTO1);
            UserDTO userByKey = userService.GetUserByKey(userDTO1.ID);
            Assert.IsTrue(userByKey.IsDisabled == false);
        }
Beispiel #6
0
        public void UpdateAllNotNullOrEmptyTest()
        {
            User user = new User("qianlifeng", "qlf", "*****@*****.**", "test", null);
            UserDTO userDTO = new UserDTO
                {
                    UserName = "******",
                    NickName = "qlf2"
                };

            User userNew = ReflectUtil.UpdateNotEmptyValues(userDTO, user);

            Assert.IsTrue(userNew.UserName == userDTO.UserName);
            Assert.IsTrue(userNew.NickName == userDTO.NickName);
            Assert.IsTrue(userNew.Email != userDTO.Email);
        }
Beispiel #7
0
 public void AddUserTest()
 {
     Assert.IsTrue(userDTO1.ID == Guid.Empty);
     userDTO1 = userService.AddUser(userDTO1);
     Assert.IsTrue(userDTO1.ID != Guid.Empty);
 }
Beispiel #8
0
        public void ValidateUserTest()
        {
            userDTO1.UserName = "******";
            userDTO1.Password = "******";
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            AdminLoginDTO dto = new AdminLoginDTO
            {
                UserName = "******",
                Password = "******"
            };

            bool canLogin = userService.ValidateUser(dto);
            Assert.IsTrue(canLogin);
        }
Beispiel #9
0
        public void UpdateUserTest()
        {
            userDTO1.UserName = "******";
            userDTO1.Password = "******";
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            userDTO1.UserName = "******";
            userDTO1 = userService.UpdateUser(userDTO1);
            Assert.IsTrue(userDTO1.UserName == "test");
        }
Beispiel #10
0
        public void MyTestInitialize()
        {
            userService = ServiceLocator.Instance.GetService<IUserService>();
            userDTO1 = new UserDTO()
                {
                    UserName = "******",
                    Password = "******",
                    DateLastLogin = DateTime.Now,
                    DateRegistered = DateTime.Now,
                    Email = "mail1",
                    IsDisabled = false,
                    NickName = "qlf1"
                };

            userDTO2 = new UserDTO()
            {
                UserName = "******",
                Password = "******",
                DateLastLogin = DateTime.Now,
                DateRegistered = DateTime.Now,
                Email = "mail2",
                IsDisabled = false,
                NickName = "qlf2"
            };
            userDTO3 = new UserDTO()
            {
                UserName = "******",
                Password = "******",
                DateLastLogin = DateTime.Now,
                DateRegistered = DateTime.Now,
                Email = "mail3",
                IsDisabled = false,
                NickName = "qlf3"
            };

            Console.WriteLine("reset db....");
            ResetDB();
        }
Beispiel #11
0
        public void GetUserByNameTest()
        {
            userDTO1.UserName = "******" + DateTime.Now;
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            UserDTO byName = userService.GetUserByName(userDTO1.UserName);
            Assert.IsTrue(userDTO1.ID == byName.ID);
        }
Beispiel #12
0
        public void GetUserByKeyTest()
        {
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            UserDTO userByEmail = userService.GetUserByKey(userDTO1.ID);
            Assert.IsTrue(userDTO1.ID == userByEmail.ID);
        }
Beispiel #13
0
        public UserDTO UpdateUser(UserDTO userDTO)
        {
            ValidateUser(userDTO);

            User user = userRepository.GetByKey(userDTO.ID);
            user = ReflectUtil.UpdateNotEmptyValues(userDTO, user);
            userRepository.Update(user);
            RepositoryContext.Commit();
            return Mapper.Map<User, UserDTO>(user);
        }
Beispiel #14
0
        public void InitDBTest()
        {
            InitAppRuntime();

            ResetDB();

            IUserService userService = ServiceLocator.Instance.GetService<IUserService>();
            UserDTO user = new UserDTO()
                {
                    UserName = "******",
                    Password = "******",
                    DateLastLogin = DateTime.Now,
                    DateRegistered = DateTime.Now,
                    Email = "mail1",
                    IsDisabled = false,
                    NickName = "qlf1"
                };
            user = userService.AddUser(user);
            Assert.IsTrue(user.ID != Guid.Empty);

            IMenuService menuService = ServiceLocator.Instance.GetService<IMenuService>();
            MenuDTO userMenu = new MenuDTO
            {
                Name = "用户管理",
                Category = "AdminMenu",
                OrderIndex = 10
            };
            MenuDTO menu = new MenuDTO
            {
                Name = "菜单管理",
                Category = "AdminMenu",
                OrderIndex = 20
            };
            userMenu = menuService.AddMenu(userMenu);
            menu = menuService.AddMenu(menu);
            Assert.IsTrue(userMenu.ID != Guid.Empty);

            MenuItemDTO menuItem1 = new MenuItemDTO
            {
                Name = "用户管理",
                URL = "#",
                OrderIndex = 10
            };
            menuItem1 = menuService.AddMenuItem(userMenu.ID, menuItem1);

            MenuItemDTO menuItem2 = new MenuItemDTO
            {
                Name = "新增菜单",
                URL = "#",
                OrderIndex = 20
            };
            MenuItemDTO menuItem3 = new MenuItemDTO
            {
                Name = "菜单列表",
                URL = "/angularTemplates/admin/menulist.html",
                OrderIndex = 30
            };
            menuItem2 = menuService.AddMenuItem(menu.ID, menuItem2);
            menuItem3 = menuService.AddMenuItem(menu.ID, menuItem3);

            Assert.IsTrue(menuItem1.ID != Guid.Empty);
        }
Beispiel #15
0
 private void ValidateUser(UserDTO userDTO)
 {
     if (userDTO == null)
         throw new ArgumentNullException("用户不能为空");
     if (userDTO.ID.IsEmptyGuid())
         throw new ArgumentNullException("用户ID不能为空");
 }
Beispiel #16
0
        public void GetUserByEmailTest()
        {
            userDTO1.Email = "meail" + DateTime.Now;
            userDTO1 = userService.AddUser(userDTO1);
            Assert.IsTrue(userDTO1.ID != Guid.Empty);

            UserDTO userByEmail = userService.GetUserByEmail(userDTO1.Email);
            Assert.IsTrue(userDTO1.ID == userByEmail.ID);
        }
Beispiel #17
0
        public List<RoleDTO> GetUserRoles(UserDTO userDTO)
        {
            ValidateUser(userDTO);

            User user = userRepository.GetByKey(userDTO.ID);
            if (user == null) throw new ApplicationException("用户不存在");

            return Mapper.Map<List<Role>, List<RoleDTO>>(user.GetAllRoles());
        }