public void ComparingWithValueAccessReturningAccessFailureReturnsFailure()
        {
            ValueAccess valueAccess = new MockValueAccess(null, null, true);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.Equal);

            ValidationResults validationResults = validator.Validate("non null");

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreEqual(1, ValidationTestHelper.GetResultsList(validationResults).Count);
        }
        public void CreatingWithValueAccessAndOperatorAndNegatedSetsValuesForValidators()
        {
            ValueAccess valueAccess = new MockValueAccess(null);
            ValueAccessComparisonValidator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.LessThan, null, true);

            Assert.AreSame(valueAccess, validator.ValueAccess);
            Assert.AreEqual(ComparisonOperator.LessThan, validator.ComparisonOperator);
            Assert.AreEqual(null, validator.Tag);
            Assert.AreEqual(true, validator.Negated);
            // Assert.AreEqual(null, validator.MessageTemplate);
        }
        public void ComparingNullForEqualityWithNonNullReturnsFailure()
        {
            ValueAccess valueAccess = new MockValueAccess("non null");
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.Equal);

            ValidationResults validationResults = validator.Validate(null);

            Assert.IsFalse(validationResults.IsValid);
        }
        public void ComparingNullForEqualWithNullReturnsSuccess()
        {
            ValueAccess valueAccess = new MockValueAccess(null);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.Equal);

            ValidationResults validationResults = validator.Validate(null);

            Assert.IsTrue(validationResults.IsValid);
        }
        public void NegatedComparisonReturnsExpectedResults()
        {
            ValueAccess valueAccess = new MockValueAccess(null);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.GreaterThanEqual, null, true);

            Assert.IsFalse(validator.Validate(5).IsValid);
            Assert.IsFalse(validator.Validate(null).IsValid);

            valueAccess = new MockValueAccess(6);
            validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.GreaterThanEqual, null, true);

            Assert.IsTrue(validator.Validate(5).IsValid);
            Assert.IsFalse(validator.Validate(6).IsValid);
            Assert.IsFalse(validator.Validate(7).IsValid);
            Assert.IsFalse(validator.Validate("string").IsValid);
            Assert.IsFalse(validator.Validate(null).IsValid);
        }
        public void SuppliesAppropriateParametersToDefaultNegatedMessage()
        {
            ValueAccess valueAccess = new MockValueAccess(5, "referenced key");
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.NotEqual, null, true);
            validator.Tag = "tag";
            object target = 6;
            string key = "key";

            ValidationResults validationResults = new ValidationResults();
            validator.DoValidate(target, null, key, validationResults);

            Assert.IsFalse(validationResults.IsValid);
            ValidationResult validationResult = ValidationTestHelper.GetResultsList(validationResults)[0];
            Match match = TemplateStringTester.Match(validator.MessageTemplate, validationResult.Message);
            Assert.IsTrue(match.Success);
            Assert.IsFalse(match.Groups["param0"].Success);
            Assert.IsFalse(match.Groups["param1"].Success);
            Assert.IsFalse(match.Groups["param2"].Success);
            Assert.IsFalse(match.Groups["param3"].Success);
            Assert.IsTrue(match.Groups["param4"].Success);
            Assert.AreEqual("referenced key", match.Groups["param4"].Value);
            Assert.IsTrue(match.Groups["param5"].Success);
            Assert.AreEqual("NotEqual", match.Groups["param5"].Value);
        }
        public void ComparingComparableForGreaterThanEqualsReturnsExpectedResults()
        {
            ValueAccess valueAccess = new MockValueAccess(7);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.GreaterThanEqual);

            Assert.IsFalse(validator.Validate(5).IsValid);
            Assert.IsFalse(validator.Validate(6).IsValid);
            Assert.IsTrue(validator.Validate(7).IsValid);
            Assert.IsTrue(validator.Validate(8).IsValid);
            Assert.IsTrue(validator.Validate(9).IsValid);
        }
        public void ComparingWithUnknownOperatorFails()
        {
            ValueAccess valueAccess = new MockValueAccess(7);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, (ComparisonOperator)100);

            Assert.IsFalse(validator.Validate(5).IsValid);
            Assert.IsFalse(validator.Validate(6).IsValid);
            Assert.IsFalse(validator.Validate(7).IsValid);
            Assert.IsFalse(validator.Validate(8).IsValid);
            Assert.IsFalse(validator.Validate(9).IsValid);
        }
        public void ComparingComparableForLessThanWithLargerOfSameTypeReturnsSuccess()
        {
            ValueAccess valueAccess = new MockValueAccess(8);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.LessThan);

            ValidationResults validationResults = validator.Validate(7);

            Assert.IsTrue(validationResults.IsValid);
        }
        public void ComparingComparableForLessThanWithSmallerOfSameTypeReturnsFailure()
        {
            ValueAccess valueAccess = new MockValueAccess(6);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.LessThan);

            ValidationResults validationResults = validator.Validate(7);

            Assert.IsFalse(validationResults.IsValid);
        }
        public void ComparingComparableForLessThanWithNullReturnsFailure()
        {
            ValueAccess valueAccess = new MockValueAccess(null);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.LessThan);

            ValidationResults validationResults = validator.Validate("a string");

            Assert.IsFalse(validationResults.IsValid);
        }
        public void ComparingNonComparableForLessThanReturnsFailure()
        {
            ValueAccess valueAccess = new MockValueAccess(7);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.LessThan);

            ValidationResults validationResults = validator.Validate(new object());

            Assert.IsFalse(validationResults.IsValid);
        }
        public void ComparingNonNullForNonEqualityWithNonEqualReturnsSuccess()
        {
            ValueAccess valueAccess = new MockValueAccess(5);
            Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.NotEqual);

            ValidationResults validationResults = validator.Validate("non null");

            Assert.IsTrue(validationResults.IsValid);
        }