/// <summary>
 /// Checks the given password to ensure that it passes the validation rules
 /// that were given in the constructor.
 /// </summary>
 /// <param name="password">The password to check against the validation rules</param>
 /// <returns>true if the validation has passed and the password is suitable;
 /// false indicates the password failed the validation.</returns>
 public bool Validate(string password)
 {
     if (password == null)
     {
         throw new ArgumentNullException("password");
     }
     return(_validationChain.Validate(password));
 }
        public void Validate_TwoChainedHandlers_LogLengthIsTwo()
        {
            var node1 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());
            var node2 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());

            node1.Successor = node2;
            node1.Validate("");
            Assert.AreEqual(2, log.Length);
        }
        public void Validate_TwoChainedHanldersFirstFails_LogLengthIsOne()
        {
            var node1 = new ValidationHandlerNode(new AlwaysFailsValidationHandler());
            var node2 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());

            node1.Successor = node2;
            node1.Validate("");
            Assert.AreEqual(1, log.Length);
            Assert.AreEqual("F", log);
        }
        public void Validate_ThreeChainedHanldersMiddleFails_LogLengthIsTwo()
        {
            var node1 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());
            var node2 = new ValidationHandlerNode(new AlwaysFailsValidationHandler());
            var node3 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());

            node1.Successor = node2;
            node2.Successor = node3;
            node1.Validate("");
            Assert.AreEqual(2, log.Length);
            Assert.AreEqual("TF", log);
        }
        public void Validate_ThreeChainedHanldersAllPass_LogLengthIsThree()
        {
            var node1 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());
            var node2 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());
            var node3 = new ValidationHandlerNode(new AlwaysPassesValidationHandler());

            node1.Successor = node2;
            node2.Successor = node3;
            bool result = node1.Validate("");

            Assert.AreEqual(3, log.Length);
            Assert.AreEqual("TTT", log);
            Assert.IsTrue(result);
        }