예제 #1
0
        public void ResetPasswordWorksProperly()
        {
            var sut = new Member()
            {
                PasswordResetToken = "bar",
                PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(20)
            };

            sut.ResetPassword("foo", "bar");

            Assert.IsTrue(sut.VerifyPassword("foo"));
            Assert.IsNull(sut.PasswordResetToken);
            Assert.IsNull(sut.PasswordResetTokenExpiration);
        }
예제 #2
0
        public void PasswordResetWorksProperly()
        {
            var authentication = new Mock<IAuthentication>();

            using (var store = NewDocumentStore())
            {
                using(var session = store.OpenSession())
                {
                    var member = new Member();
                    member.UserName = "******";
                    member.PasswordResetToken = "foo";
                    member.PasswordResetTokenExpiration = DateTimeOffset.UtcNow.AddMinutes(20);

                    session.Store(member);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var command = new MemberPasswordResetCommand
                    {
                        Password = "******",
                        Token = "foo",
                        UserName = "******"
                    };

                    var members = new Mock<IFindMembers>();
                    members.Setup(x => x.FindMemberByUserName(It.IsAny<string>()))
                           .Returns(session.Load<Member>(Member.FormatId(command.UserName)));

                    var sut = new MemberPasswordResetController(session, members.Object, authentication.Object);
                    sut.Post(command);
                }

                using (var session = store.OpenSession())
                {
                    var member = session.Load<Member>(Member.FormatId("john.doe"));

                    Assert.IsTrue(member.VerifyPassword("a new password"));
                    authentication.Verify(x => x.Login(Member.FormatId("john.doe")), Times.Once);
                }
            }
        }