public void CreateNewUser_Returns_False_If_User_Exists()
        {
            // arrange
            var usersRepository = new Mock<IUsersRepository>();
            var forms = new Mock<IFormsAuthentication>();
            var hash = new HashService();
            var service = new AuthenticationService(usersRepository.Object, forms.Object, hash);

            var users = new List<User>();
            usersRepository.Setup(u => u.Users).Returns(users.AsQueryable());
            usersRepository.Setup(u => u.Save(It.IsAny<User>())).Callback((User u) => users.Add(u));

            // act
            service.RegisterNewUser("*****@*****.**", "mypass");
            var result = service.RegisterNewUser("*****@*****.**", "mypass");

            // assert
            Assert.That(result, Is.False);
        }
        public void CreateNewUser_ApiToken_Created()
        {
            // arrange
            var usersRepository = new Mock<IUsersRepository>();
            var forms = new Mock<IFormsAuthentication>();
            var hash = new HashService();
            var service = new AuthenticationService(usersRepository.Object, forms.Object, hash);

            var users = new List<User>();
            usersRepository.Setup(u => u.Users).Returns(users.AsQueryable());
            usersRepository.Setup(u => u.Save(It.IsAny<User>())).Callback((User u) => users.Add(u));

            // act
            service.RegisterNewUser("*****@*****.**", "mypass");

            // assert
            Assert.That(users.Count, Is.GreaterThan(0));
            var found = users.Find((u) => u.Email == "*****@*****.**");
            Assert.That(found.ApiToken.Length, Is.EqualTo(32));

        }
        public void CreateNewUser_User_Immediately_Auhtenticated()
        {
            //arrange
            var usersRepository = new Mock<IUsersRepository>();
            var forms = new Mock<IFormsAuthentication>();
            var hash = new HashService();
            var service = new AuthenticationService(usersRepository.Object, forms.Object, hash);

            var users = new List<User>();
            usersRepository.Setup(u => u.Users).Returns(users.AsQueryable());
            usersRepository.Setup(u => u.Save(It.IsAny<User>())).Callback((User u) => users.Add(u));

            // act
            service.RegisterNewUser("*****@*****.**", "mypass");

            // assert
            Assert.That(users.Count, Is.GreaterThan(0));
            forms.Verify(f => f.SetAuthCookie("*****@*****.**", false));
        }