コード例 #1
0
        public void Login_given_null_CryptoService_throws_ArgumentNullException()
        {
            // arrange
            User user = new User();

            // assert
            Assert.Throws<ArgumentNullException>(() => user.Login(null, "password"));
        }
コード例 #2
0
        public void Login_given_null_or_whitespace_password_throws_ArgumentException(string password)
        {
            // arrange
            ICryptoService cryptoService = MockRepository.GenerateStub<ICryptoService>();
            User user = new User();

            // assert
            Assert.Throws<ArgumentException>(() => user.Login(cryptoService, password));
        }
コード例 #3
0
        public User Update(User user, string password = null)
        {
            Guard.Against<InvalidOperationException>(() => user.ID == 0, "You may only update existing users. Call Create() to save a new User.");

            if(!string.IsNullOrWhiteSpace(password))
            {
                user.SetPassword(this.cryptoService, password);
            }

            User saved = this.userRepository.Save(user);

            return saved;
        }
コード例 #4
0
        public void Login_when_unsuccessful_returns_false_and_sets_LastActive()
        {
            // arrange
            ICryptoService cryptoService = MockRepository.GenerateStub<ICryptoService>();
            cryptoService.Expect(x => x.VerifyPassword("salt", "hash", "password")).Return(false);

            User user = new User
                        {
                            Email = "Email",
                            PasswordSalt = "salt",
                            PasswordHash = "hash",
                        };

            // act
            bool loggedIn = user.Login(cryptoService, "password");

            // assert
            Assert.IsFalse(loggedIn);

            cryptoService.VerifyAllExpectations();
        }
コード例 #5
0
        public void UserMappingTest()
        {
            // arrange
            User expected = new User
                            {
                                PasswordSalt = "PasswordSalt",
                                PasswordHash = "PasswordHash",
                                Email = "Email",
                            };

            // act
            using(ISession session = this.sessionFactory.OpenSession())
            {
                using(ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(expected);
                    transaction.Commit();
                }
            }

            User actual;

            using(ISession session = this.sessionFactory.OpenSession())
            {
                using(session.BeginTransaction())
                {
                    actual = session.Get<User>(expected.ID);
                }
            }

            // assert
            Assert.That(actual != expected);
            Assert.That(actual.ID == expected.ID);
            Assert.That(actual.PasswordSalt == expected.PasswordSalt);
            Assert.That(actual.PasswordHash == expected.PasswordHash);
        }