public void Test_ValidateByUserName_UserNotExists()
        {
            var customerProvider = new Mock<ICustomerProvider>();
            var customerService = new Mock<ICustomerService>();
            var passwordEncryptor = new Mock<IPasswordEncryptor>();

            CustomerMembershipService customerMemberhipService = new CustomerMembershipService(
                customerProvider.Object, customerService.Object, passwordEncryptor.Object);

            var result = customerMemberhipService.ValidateByUserName("test", "test");
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Username and/or password are incorrect.", result.Errors[0]);
        }
        public void Test_ValidateByUserName_PasswordInvalid_WithLockedOut()
        {
            var customer = new Customer()
               {
                   Username = "******",
                   Membership = new Membership()
                   {
                       IsLockedOut = false,
                       IsApproved = true,
                       Password = "******",
                       FailedPasswordAttemptCount = 4
                   }
               };
            var customerProvider = new Mock<ICustomerProvider>();
            customerProvider.Setup(it => it.QueryByUserName("test"))
               .Returns(customer);
            var customerService = new Mock<ICustomerService>();
            var passwordEncryptor = new Mock<IPasswordEncryptor>();

            CustomerMembershipService customerMemberhipService = new CustomerMembershipService(
                customerProvider.Object, customerService.Object, passwordEncryptor.Object);

            var result = customerMemberhipService.ValidateByUserName("test", "test");
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Username and/or password are incorrect.", result.Errors[0]);

            Assert.AreEqual(5, customer.Membership.FailedPasswordAttemptCount);
            Assert.IsTrue(customer.Membership.IsLockedOut);
        }
        public void Test_ValidateByUserName_Return_True()
        {
            var customer = new Customer()
                {
                    Username = "******",
                    Membership = new Membership()
                    {
                        IsLockedOut = false,
                        IsApproved = true,
                        Password = "******"
                    }
                };
            var customerProvider = new Mock<ICustomerProvider>();
            customerProvider.Setup(it => it.QueryByUserName("test"))
                .Returns(customer);
            var customerService = new Mock<ICustomerService>();
            var passwordEncryptor = new Mock<IPasswordEncryptor>();
            passwordEncryptor.Setup(it => it.EncryptPassword("test", null))
                .Returns("test");

            CustomerMembershipService customerMemberhipService = new CustomerMembershipService(
                customerProvider.Object, customerService.Object, passwordEncryptor.Object);

            Assert.IsTrue(customerMemberhipService.ValidateByUserName("test", "test").Success);

            Assert.AreEqual(0, customer.Membership.FailedPasswordAttemptCount);
        }
        public void Test_ValidateByUserName_LockedOut()
        {
            var customerProvider = new Mock<ICustomerProvider>();
            customerProvider.Setup(it => it.QueryByUserName("test"))
               .Returns(new Customer()
               {
                   Username = "******",
                   Membership = new Membership()
                   {
                       IsLockedOut = true,
                       IsApproved = true,
                       Password = "******"
                   }
               }
               );
            var customerService = new Mock<ICustomerService>();
            var passwordEncryptor = new Mock<IPasswordEncryptor>();
            passwordEncryptor.Setup(it => it.EncryptPassword("test", null))
               .Returns("test");
            CustomerMembershipService customerMemberhipService = new CustomerMembershipService(
                customerProvider.Object, customerService.Object, passwordEncryptor.Object);

            var result = customerMemberhipService.ValidateByUserName("test", "test");
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Account was locked out or not approved.", result.Errors[0]);
        }