Exemplo n.º 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");
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
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);
        }