public void CanCreateUser()
        {
            var userRepo = new Mock<IUserRepository>(MockBehavior.Strict);
            var newUser = new User
            {
                UserName = "******",
                Password = "******",
                Email = "Email",
                FirstName = "You",
                LastName = "Me"
            };

            userRepo.Setup(e => e.FindByEmail(newUser.Email)).Returns((User)null);
            userRepo.Setup(e =>
                e.Save(It.Is<User>(user => user.Email.Equals(newUser.Email)
                                       && user.UserName.Equals(newUser.UserName)
                                       && user.LastName.Equals(newUser.LastName)
                                       && user.FirstName.Equals(newUser.FirstName)
                                       && user.Password.Equals(newUser.Password))))
                .Returns(new DatabaseOperationResponse(true));

            MembershipCreateStatus status;

            new CharcoalMembershipProvider(userRepo.Object)
                .CreateUser(newUser.UserName,
                newUser.Password, newUser.Email,
                newUser.FirstName, newUser.LastName,
                false, null, out status);
            Assert.AreEqual(MembershipCreateStatus.Success, status);
            userRepo.Verify();
        }
Exemplo n.º 2
0
        public void CanFindAll()
        {
            var user = new User();
            user.APIKey = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.LastName = "loooe3rewrrewooooo";
            user.FirstName = "dsfsdf";
            user.Password = "******";
            user.Privileges = Privilege.Product;
            user.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user);
            Assert.IsTrue(response.HasSucceeded);

            User retrievedUser = m_database.Users.All().ToList<User>()[0];
            m_database.Projects.Insert(Title: "wololo", Description: "blah");

            long projectId = m_database.Projects.All().ToList<Project>()[0].Id;

            m_database.UsersXProjects.Insert(UserId: retrievedUser.Id,
                                             ProjectId: projectId);

            List<User> foundUsers = m_repository.FindAll().ConvertAll(e=> (User)e);
            Assert.AreEqual(1, foundUsers.Count);

            VerifyUserStory(retrievedUser, foundUsers[0]);
            Assert.NotNull(foundUsers[0].Projects);
            Assert.AreEqual(1, foundUsers[0].Projects.Count);
            Assert.AreEqual(projectId, foundUsers[0].Projects[0].Id);
        }
        public void CanGetUserAPI()
        {
            var userRepo = new Mock<IUserRepository>(MockBehavior.Strict);
            var user = new User { UserName = "******", Password = "******", APIKey = "jawn" };
            userRepo.Setup(e => e.GetAPIKey(user.UserName, user.Password)).Returns(user.APIKey);

            var apiKey = new CharcoalMembershipProvider(userRepo.Object).GetPassword(user.UserName, user.Password);
            Assert.AreEqual(user.APIKey, apiKey);
            userRepo.Verify();
        }
Exemplo n.º 4
0
        public void CanFindByEmail()
        {
            var user = new User();
            user.APIKey = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.LastName = "loooe3rewrrewooooo";
            user.FirstName = "dsfsdf";
            user.Privileges = Privilege.Product;
            user.Password = "******";
            user.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user);
            Assert.IsTrue(response.HasSucceeded);

            User foundUser = m_repository.FindByEmail(user.Email);
            VerifyUserStory(user, foundUser);
        }
Exemplo n.º 5
0
        public void CanDeleteExistingStory()
        {
            var user = new User();
            user.APIKey = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.LastName = "loooe3rewrrewooooo";
            user.FirstName = "dsfsdf";
            user.Password = "******";
            user.Privileges = Privilege.Product;
            user.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user);
            Assert.IsTrue(response.HasSucceeded);

            User retrievedUser = m_database.Users.All().ToList<User>()[0];
            response = m_repository.Delete(retrievedUser.Id);

            Assert.IsTrue(response.HasSucceeded);

            var stories = m_database.Users.All().ToList<User>();
            Assert.AreEqual(0, stories.Count);
        }
Exemplo n.º 6
0
 public MemberViewModel(User user)
 {
     UserName = user.UserName;
     Email = user.Email;
     Id = user.Id;
 }
Exemplo n.º 7
0
 private void VerifyUserStory(User expected, User actual)
 {
     Assert.AreEqual(expected.Email, actual.Email);
     Assert.AreEqual(expected.UserName, actual.UserName);
     Assert.AreEqual(expected.FirstName, actual.FirstName);
     Assert.AreEqual(expected.LastName, actual.LastName);
     Assert.AreEqual(expected.APIKey, actual.APIKey);
     Assert.AreEqual(expected.Privileges,(Privilege) actual.Privileges);
 }
Exemplo n.º 8
0
        public void CanValidateUser()
        {
            var user = new User();
            user.APIKey = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.LastName = "loooe3rewrrewooooo";
            user.FirstName = "dsfsdf";
            user.Password = "******";
            user.Privileges = Privilege.Developer | Privilege.Product;
            user.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user);
            Assert.IsTrue(response.HasSucceeded);

            Assert.IsTrue(m_repository.IsValid(user.UserName,user.Password));
        }
Exemplo n.º 9
0
        public void CanSaveUser()
        {
            var user = new User();
            user.APIKey = Guid.NewGuid().ToString();
            user.UserName = "******";
            user.LastName = "loooe3rewrrewooooo";
            user.FirstName = "dsfsdf";
            user.Password = "******";
            user.Privileges = Privilege.Developer | Privilege.Product;
            user.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user);
            Assert.IsTrue(response.HasSucceeded);

            var users = m_database.Users.All().ToList<User>();
            Assert.AreEqual(1, users.Count);

            VerifyUserStory(user, users[0]);
        }
Exemplo n.º 10
0
        public void CannotGetAllUsers_With_NonExisting_ApiKey()
        {
            var user1 = new User();
            user1.APIKey = Guid.NewGuid().ToString();
            user1.UserName = "******";
            user1.LastName = "loooe3rewrrewooooo";
            user1.FirstName = "dsfsdf";
            user1.Password = "******";
            user1.Privileges = Privilege.Developer | Privilege.Product;
            user1.Email = "*****@*****.**";

            var response = m_repository.Save(user1);
            Assert.IsTrue(response.HasSucceeded);

            var users = m_repository.GetAllUsers(Guid.NewGuid().ToString());
            Assert.AreEqual(0, users.Count);
        }
Exemplo n.º 11
0
        public void CanGetAllUsers_With_Existing_ApiKey()
        {
            var user1 = new User();
            user1.APIKey = Guid.NewGuid().ToString();
            user1.UserName = "******";
            user1.LastName = "loooe3rewrrewooooo";
            user1.FirstName = "dsfsdf";
            user1.Password = "******";
            user1.Privileges = Privilege.Developer | Privilege.Product;
            user1.Email = "*****@*****.**";

            DatabaseOperationResponse response = m_repository.Save(user1);
            Assert.IsTrue(response.HasSucceeded);
            var user2 = new User();
            user2.APIKey = Guid.NewGuid().ToString();
            user2.UserName = "******";
            user2.LastName = "loooe3rewrrewooooo";
            user2.FirstName = "dsfsdf";
            user2.Password = "******";
            user2.Privileges = Privilege.Developer | Privilege.Product;
            user2.Email = "*****@*****.**";

             response = m_repository.Save(user2);
            Assert.IsTrue(response.HasSucceeded, response.Description);

            var users = m_repository.GetAllUsers(user2.APIKey);
            Assert.AreEqual(2, users.Count);
            Assert.IsTrue(users.Exists(e=> e.APIKey == user1.APIKey));
            Assert.IsTrue(users.Exists(e => e.APIKey == user2.APIKey));
        }
Exemplo n.º 12
0
 public OperationResponse CreateUser(User user)
 {
     MembershipCreateStatus createStatus;
     Membership.CreateUser(user.UserName, user.Password, user.Email, user.FirstName, user.LastName, false, null, out createStatus);
     return new OperationResponse(createStatus == MembershipCreateStatus.Success);
 }
        public override MembershipUser CreateUser(string username, string password, string email,
                                                  string firstame, string lastName, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && !string.IsNullOrWhiteSpace(GetUserNameByEmail(email)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var user = new User
            {
                UserName = username,
                Password = password,
                Email = email,
                FirstName = firstame,
                LastName = lastName
            };
            var response = UserRepository.Save(user);
            status = response.HasSucceeded ? MembershipCreateStatus.Success
                                           : MembershipCreateStatus.UserRejected;
            return null;
        }