예제 #1
0
        public void When_ValidateUser_is_called_with_a_valid_UserName_and_a_valid_Password_then_true_is_returned()
        {
            const string decryptedPassword = "******";
            var          user = UserCreator.CreateSingle();

            UserProcess
            .Expect(process =>
                    process.GetUserByLoginName(user.Login.LoginName))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            CryptographyProcess
            .Expect(process => process.Decrypt(user.Login.Password))
            .Return(decryptedPassword)
            .Repeat.Once();
            CryptographyProcess.Replay();

            var result = CustomMembershipProvider.ValidateUser(user.Login.LoginName, decryptedPassword);

            UserProcess.VerifyAllExpectations();
            CryptographyProcess.VerifyAllExpectations();

            Assert.IsTrue(result);
        }
예제 #2
0
        public void When_CreatUser_is_called_then_the_User_is_created_and_registered_under_the_Band_that_is_provided_by_the_BandProcess()
        {
            var          band              = BandCreator.CreateSingle();
            var          user              = UserCreator.CreateSingle();
            var          login             = user.Login;
            const string encryptedPassword = "******";

            BandProcess
            .Expect(process => process.EnsureBandExists())
            .Return(band)
            .Repeat.Once();
            BandProcess.Replay();

            CryptographyProcess
            .Expect(process => process.Encrypt(login.Password))
            .Return(encryptedPassword)
            .Repeat.Once();
            CryptographyProcess.Replay();

            UserProcess
            .Expect(process => process.GetUserByLoginName(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process => process.GetUserByEmailAddress(Arg <string> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            UserProcess
            .Expect(process =>
                    process.AddUser(Arg <User> .Matches(u =>
                                                        u.BandId == band.Id &&
                                                        u.Login.Password == encryptedPassword &&
                                                        u.Login.IsOnline &&
                                                        u.Login.LastLoginDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastActivityDate > DateTime.UtcNow.AddSeconds(-2) &&
                                                        u.Login.LastPasswordChangedDate >
                                                        DateTime.UtcNow.AddSeconds(-2))))
            .Return(user)
            .Repeat.Once();
            UserProcess.Replay();

            var membershipUser = CreateMembershipUser(user);

            UserMapper
            .Expect(mapper => mapper.Map(user))
            .Return(membershipUser)
            .Repeat.Once();
            UserMapper.Replay();

            MembershipCreateStatus createStatus;
            var result = CustomMembershipProvider.CreateUser(
                login.LoginName,
                login.Password,
                login.EmailAddress,
                string.Empty,
                string.Empty,
                login.IsApproved,
                login.Id,
                out createStatus);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ProviderUserKey);
            Assert.AreEqual(user.Login.LoginName, result.UserName);
            Assert.AreEqual(MembershipCreateStatus.Success, createStatus);

            BandProcess.VerifyAllExpectations();
            CryptographyProcess.VerifyAllExpectations();
            UserProcess.VerifyAllExpectations();
            UserMapper.VerifyAllExpectations();
        }