private void AddUserWithDefaultRoles(User user)
        {
            Role addedUserRole = testDBContext.Roles.Where(r => r.Name.Equals(UserRoleName)).FirstOrDefault() as Role;
            Role addedAdminRole = testDBContext.Roles.Where(r => r.Name.Equals(AdministratorRoleName)).FirstOrDefault() as Role;

            UserRole userUserRole = new UserRole()
            {
                RoleId = addedUserRole.RoleId
            };
            UserRole adminUserRole = new UserRole()
            {
                RoleId = addedAdminRole.RoleId
            };

            user.UserRoles = new List<UserRole>() { userUserRole, adminUserRole };
            AddUser(user);
        }
        public void Add_User_Role()
        {
            // Prepare
            AddDefaultRoles();

            User newUser = new User()
            {
                NameIdentifier = "s0Me1De9Tf!Er$tRing",
                FirstName = "SomeFirstName",
                MiddleName = "SomeMiddleName",
                LastName = "SomeLastName",
                IdentityProvider = "Windows Live",
                Organization = "SomeOrganization",
                EmailId = "*****@*****.**",
                CreatedOn = DateTime.Now,
                ModifiedOn = DateTime.Now,
                IsActive = true
            };
            AddUser(newUser);
            User addedUser = testDBContext.Users.Find(1);
            UserRole userRole = new UserRole()
            {
                UserId = addedUser.UserId,
                RoleId = GetUserRoleId()
            };

            // Perform
            IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork);
            UserRole addedUserRole = repository.AddUserRole(userRole);

            // Check if a valid user role is returned
            Assert.IsNotNull(addedUserRole);

            // Check if the count of tracked objects is 1
            Assert.IsTrue(testDBContext.UserRoles.Local.Count == 1);

            // Check is the entity state of the added object is set to Added
            Assert.AreEqual(testDBContext.GetEntityState(addedUserRole), EntityState.Added);
        }
        public void Get_Existing_User_By_NameIdentifier()
        {
            AddDefaultRoles();
            User newUser = new User()
            {
                NameIdentifier = "s0Me1De9Tf!Er$tRing",
                FirstName = "SomeFirstName",
                MiddleName = "SomeMiddleName",
                LastName = "SomeLastName",
                IdentityProvider = "Windows Live",
                Organization = "SomeOrganization",
                EmailId = "*****@*****.**",
                CreatedOn = DateTime.Now,
                ModifiedOn = DateTime.Now,
                IsActive = true
            };
            AddUser(newUser);
            UserRole userRole = new UserRole()
            {
                UserId = 1,
                RoleId = 1
            };
            testDBContext.UserRoles.Add(userRole);
            testDBContext.Commit();

            // Perform get
            IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork);
            User retrievedUser = repository.GetUserByNameIdentifier(newUser.NameIdentifier);

            // Check if a valid user is returned
            Assert.IsNotNull(retrievedUser);

            // Check if the name identifier matches
            Assert.AreEqual(newUser.NameIdentifier, retrievedUser.NameIdentifier);
        }
 public UserRole AddUserRole(UserRole userRole)
 {
     Check.IsNotNull<UserRole>(userRole, "userRole");
     return Context.UserRoles.Add(userRole);
 }