public void VerifiesTheSubmittedPasswordAgainstTheStoredOne()
        {
            var store = A.Fake<IDataStore>();
            var encryption = A.Fake<IEncryption>();
            var user = new User {Password = "******"};

            Any.CallTo(store).WithReturnType<User>().Returns(user);
            new UserRepository(store, encryption).FindByCredentials(null, "Duncan");

            A.CallTo(() => encryption.CheckPassword("Ghanima", "Duncan")).MustHaveHappened();
        }
        public void Returns_null_when_the_password_does_not_match()
        {
            var expectedUser = new User { Password = "******" };

            ThisUsernameReturnsThisUser("un", expectedUser);
            ThisEncryptedAndDecryptedPasswordDoNotMatch("another encrypted password", "pw");

            var result = GetTheUser("un", "pw");

            result.ShouldBeNull();
        }
        public void Returns_a_user_when_the_username_and_password_are_valid()
        {
            var expectedUser = new User { Password = "******" };

            ThisUsernameReturnsThisUser("Username", expectedUser);
            ThisEncryptedAndDecryptedPasswordWillMatch("My Encrypted Password", "Password");

            var result = GetTheUser("Username", "Password");

            result.ShouldBeSameAs(expectedUser);
        }
        public void ReturnTheValidUser()
        {
            var store = A.Fake<IDataStore>();
            var encryption = A.Fake<IEncryption>();
            var expected = new User();

            Any.CallTo(store).WithReturnType<User>().Returns(expected);
            Any.CallTo(encryption).WithReturnType<bool>().Returns(true);
            var user = new UserRepository(store, encryption).FindByCredentials(null, null);

            Assert.AreSame(expected, user);
        }
 private void ThisUsernameReturnsThisUser(string username, User user)
 {
     mocker.GetMock<IDataStore>()
         .Setup(x => x.FindOneByNamedQuery("FindUserByUserName", username))
         .Returns(user);
 }