예제 #1
0
        public void Add_User_With_No_Username()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var userStore = new UserStore(context, encrpytor.Object);

            userStore.AddUser(new User { Username = "" }, "Password");
        }
예제 #2
0
        public void Authenticate_No_User()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var users = new Mock<DbSet<User>>();
            var userStore = new UserStore(context, encrpytor.Object);

            Assert.IsFalse(userStore.Authenticate("test", "test"));
        }
예제 #3
0
        public void Add_Duplicate_Username()
        {
            var context = new MockContext();
            context.Users.Add(
                new User { Username= "******"}
            );
            var encryptor = new Mock<IEncryptor>();
            var userStore = new UserStore(context, encryptor.Object);

            userStore.AddUser(new User { Username = "******" }, "password");
        }
예제 #4
0
        public void Authenticate_User()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            var salt = new byte[] { 1 };
            var password = new byte[] { 1, 2, 3, 4};
            context.Users.Add(new User{
                Username = "******", Password = password, Salt = salt
            });
            encrpytor.Setup(e => e.GetPassword(salt, "test")).Returns(new byte[] { 1, 2, 3, 4 });

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

            Assert.IsTrue(userStore.Authenticate("test", "test"));
        }
예제 #5
0
        public void Change_Email()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();
            context.Users.Add(new User { Username = "******", Email = "*****@*****.**" });

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

            userStore.ChangeEmail("test", "*****@*****.**");

            var user = context.Users.First();
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
예제 #6
0
        public void Authenticate_User_Wrong_Password()
        {
            var context = new MockContext();
            var encrpytor = new Mock<IEncryptor>();
            context.Users.Add(new User { Username = "******", Password = new byte[] { 1, 2 }});
            var userStore = new UserStore(context, encrpytor.Object);

            Assert.IsFalse(userStore.Authenticate("test", "test"));
        }
예제 #7
0
        public void Password_Gets_Encrypted()
        {
            var salt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var password = new byte[] { 5, 6, 7, 8 };
            var encryptor = new Mock<IEncryptor>();
            var context = new MockContext();

            encryptor.Setup(e => e.GetSalt()).Returns(salt);
            encryptor.Setup(e => e.GetPassword(salt, "Password")).Returns(password);

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

            userStore.AddUser(new User{ Username = "******" }, "Password");

            encryptor.Verify(e => e.GetSalt(), Times.Once);
            encryptor.Verify(e => e.GetPassword(salt, "Password"), Times.Once);

            Assert.AreEqual(1, context.Users.Count());
            var user = context.Users.First();
            Assert.AreEqual("test", user.Username);
            Assert.AreEqual(password, user.Password);
            Assert.AreEqual(salt, user.Salt);
            Assert.AreEqual(1, context.SaveChangesCalls);
        }
예제 #8
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");
        }
예제 #9
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);
        }
예제 #10
0
        public void Change_Email_User_Not_Found()
        {
            var context = new MockContext();
            var encryptor = new Mock<IEncryptor>();

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

            userStore.ChangeEmail("test", "*****@*****.**");
        }