示例#1
0
        public void Change_Password_User_Not_Found()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangePassword("test", "newPassword");
        }
示例#2
0
        public void Change_Password()
        {
            var context = new MockContext();
            context.Users.Add(new User
            {
                Username = "******",
                Password = new byte[] {1,2,3,4},
                Salt = new byte[] {1,2}
            });

            var encryptor = new Mock<IEncryptor>();
            encryptor.Setup(e => e.GetSalt()).Returns(new byte[] { 3, 4 });
            encryptor.Setup(e => e.GetPassword(new byte[] { 3, 4 }, "newPassword")).Returns(new byte[] { 5, 6, 7, 8 });

            var userStore = new UserStore(context, encryptor.Object);

            userStore.ChangePassword("test", "newPassword");

            encryptor.Verify(e => e.GetPassword(new byte[] { 3, 4 }, "newPassword"), Times.Once);
            encryptor.Verify(e => e.GetSalt(), Times.Once);
            var user = context.Users.First();
            Assert.AreEqual("test", user.Username);
            Assert.AreEqual(new byte[] { 5, 6, 7, 8 }, user.Password);
            Assert.AreEqual(new byte[] { 3, 4 }, user.Salt);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }