Esempio n. 1
0
 public void Validation()
 {
     role = new Role()
                {
                    RoleId = 1,
                    RoleName = "FakeRole",
                    Version = 0
                };
     Assert.IsTrue(role.IsValid, "Should be valid");
 }
        public void TestGetUserByCriteria()
        {
            SecurityBusinessComponent service = new SecurityBusinessComponent(this.context);
            Role role = new Role() {RoleId = 12345, RoleName = "FakeRoleName"};
            User user = new User {UserId = 456, UserName = "FakeUserName", 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 TestUserToDto()
        {
            User user = new User() {UserId = 1, UserName = "FakeName", Password = "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);
        }
Esempio n. 4
0
 private static Role DtoToRole(RoleDTO dto)
 {
     Role role = new Role()
                     {
                         RoleId = dto.Id,
                         RoleName = dto.RoleName,
                         Version = dto.Version
                     };
     ValidationHelper.Validate(role);
     return role;
 }
Esempio n. 5
0
 public static RoleDTO RoleToDTO(Role r)
 {
     RoleDTO dto = new RoleDTO()
                       {
                           Id = r.RoleId,
                           RoleName = r.RoleName,
                           Version = r.Version
                       };
     return dto;
 }
Esempio n. 6
0
 public void ValidationFails()
 {
     role = new Role();
     Assert.IsFalse(role.IsValid, "Should be invalid");
 }
Esempio n. 7
0
 public void Build()
 {
     role = new Role();
     Helper.AssertEmptiness(role, "RoleId", "RoleName");
 }
Esempio n. 8
0
 public void TearDown()
 {
     role = null;
 }
Esempio n. 9
0
 public void SetUp()
 {
     role = new Role();
 }