Beispiel #1
0
 public void Build()
 {
     user = new User();
     Helper.AssertEmptiness(user, "UserId", "UserName" /*, "Password"*/, "Roles");
     Assert.AreNotEqual<int>(0, user.Password.ToString().Count());
     Assert.IsNull(user.Customer);
 }
        public int StoreUser(User user, IEnumerable<ChangeItem> changeItems)
        {
            int userId = default(int);
            using (TransactionScope transaction = new TransactionScope())
            {
                userId = rep.SaveUser(user);

                foreach (ChangeItem item in changeItems)
                {
                    if (item.Object is Role)
                    {
                        Role role = (Role) item.Object;
                        switch (item.ChangeType)
                        {
                            case ChangeType.ChildInsert:
                            case ChangeType.ChildUpate:
                                rep.AddUserToRole(user, role);
                                break;
                            case ChangeType.ChildDelete:
                                rep.RemoveUserFromRole(user, role);
                                break;
                        }
                    }
                }

                transaction.Complete();
            }
            return userId;
        }
        public void TestGetUserById()
        {
            SecurityBusinessComponent service = new SecurityBusinessComponent(this.context);
            User user = new User() {UserId = 123};

            Expect.Once.On(context).Method("GetUserById").Will(Return.Value(user));
            User resultUser = service.GetUserById(123);
            Assert.AreEqual<decimal>(user.UserId, resultUser.UserId);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
Beispiel #4
0
 public void Validation()
 {
     user = new User()
                {
                    UserId = 1,
                    UserName = "******",
                    Password = "******",
                    Version = 0
                };
     Assert.IsTrue(user.IsValid, "Should be valid");
 }
        public static CurrentUserDTO UserToCurrentUserDTO(User user)
        {
            CurrentUserDTO dto = new CurrentUserDTO()
                                     {
                                         Id = user.UserId,
                                         UserName = user.UserName,
                                         CustomerId = (user.Customer == null) ? 0 : user.Customer.CustomerId,
                                         CustomerName = (user.Customer == null) ? string.Empty : user.Customer.ToString(),
                                         Roles = RolesToDTOs(user.Roles)
                                     };

            return dto;
        }
 private static UserListDTO UserToListDto(User u)
 {
     UserListDTO user = new UserListDTO()
                            {
                                Id = u.UserId,
                                UserName = u.UserName,
                                Roles = RolesAsString(u.Roles)
                            };
     if (u.Customer != null)
     {
         user.CustomerName = u.Customer.ToString();
     }
     return user;
 }
        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 void TestUsersToDtos()
        {
            User user = new User() {UserId = 1, UserName = "******", Password = "******", Version = 0};
            Assert.AreEqual(true, user.IsValid);

            IQueryable<User> users = new List<User>() {user}.AsQueryable();
            IList<UserListDTO> userDtos = SecurityAdapter.UsersToDtos(users);
            Assert.AreEqual<int>(1, userDtos.Count());

            UserListDTO dto = userDtos.First();
            Assert.AreEqual<int>(user.UserId, dto.Id);
            Assert.AreEqual<string>(user.UserName, dto.UserName);
            //Assert.AreEqual<string>(user.Customer.ToString(), dto.CustomerName);
            Assert.AreEqual(true, dto.IsValid);
        }
        public CustomPrincipal(IIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }
            _identity = identity;

            sb = DependencyInjectionHelper.GetSecurityBusinessComponent();
            this._user = sb.GetUserByName(identity.Name);

            if (_user == null)
            {
                throw new Exception("unknown user");
            }
        }
        public void TestGetUserByCriteria()
        {
            SecurityBusinessComponent service = new SecurityBusinessComponent(this.context);
            Role role = new Role() {RoleId = 12345, RoleName = "FakeRoleName"};
            User user = new User {UserId = 456, UserName = "******", Roles = new List<Role> {role}.AsQueryable()};
            IList<User> users = new List<User>();
            users.Add(user);

            foreach (UserSearchType type in Enum.GetValues(typeof (UserSearchType)))
            {
                Expect.Once.On(context).Method("GetAllUsers").Will(Return.Value(users.AsQueryable()));
                IQueryable<User> resultUsers = service.GetUsersByCriteria(type, "FakeUserName", "FakeRoleName");
                Assert.AreEqual<decimal>(1, resultUsers.Count());
                Assert.AreEqual<decimal>(user.UserId, resultUsers.First().UserId);
            }

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestStoreUser()
        {
            int userId = 123;
            SecurityBusinessComponent service = new SecurityBusinessComponent(this.context);
            User user = new User() {UserId = userId};
            List<ChangeItem> changeItems = new List<ChangeItem>
                                               {
                                                   new ChangeItem(ChangeType.ChildInsert, new Role()),
                                                   new ChangeItem(ChangeType.ChildUpate, new Role()),
                                                   new ChangeItem(ChangeType.ChildDelete, new Role())
                                               };

            Expect.Once.On(context).Method("SaveUser").Will(Return.Value(userId));
            Expect.Once.On(context).Method("AddUserToRole");
            Expect.Once.On(context).Method("AddUserToRole");
            Expect.Once.On(context).Method("RemoveUserFromRole");
            int resultUserId = service.StoreUser(user, changeItems);
            Assert.AreEqual<int>(userId, resultUserId);

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestUserToDto()
        {
            User user = new User() {UserId = 1, UserName = "******", Password = "******", Version = 0};
            Role role = new Role() {RoleId = 1, RoleName = "FakeRoleName", Version = 0};
            user.Roles = new List<Role>() {role}.AsQueryable();
            Assert.AreEqual(true, user.IsValid);
            Assert.AreEqual(true, role.IsValid);

            UserDTO dto = SecurityAdapter.UserToDTO(user);
            Assert.AreEqual<int>(user.UserId, dto.Id);
            Assert.AreEqual<string>(user.UserName, dto.UserName);
            Assert.AreEqual<string>(user.Password, dto.Password);
            Assert.AreEqual(user.Version, dto.Version);
            Assert.AreEqual<int>(1, dto.Roles.Count());

            RoleDTO dtoRole = dto.Roles.First();
            Assert.AreEqual<int>(role.RoleId, dtoRole.Id);
            Assert.AreEqual<String>(role.RoleName, dtoRole.RoleName);
            Assert.AreEqual(role.Version, dtoRole.Version);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, dtoRole.IsValid);
        }
 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;
 }
Beispiel #14
0
 public void ValidationFails()
 {
     user = new User();
     Assert.IsFalse(user.IsValid, "Should be invalid");
 }
Beispiel #15
0
 public void TearDown()
 {
     user = null;
 }
Beispiel #16
0
 public void SetUp()
 {
     user = new User();
 }