public void SuppliesAppropriateParametersToDefaultMessage() { ValueAccess valueAccess = new MockValueAccess(5, "referenced key"); Validator validator = new ValueAccessComparisonValidator(valueAccess, ComparisonOperator.Equal); 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]; System.Text.RegularExpressions.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("Equal", match.Groups["param5"].Value); }
public void SuppliesAppropriateParametersToMessageTemplate() { DomainValidator <int> validator = new DomainValidator <int>(false, 1, 2, 3, 4); validator.MessageTemplate = "{0}-{1}-{2}"; validator.Tag = "tag"; object target = 24; string key = "key"; ValidationResults validationResults = new ValidationResults(); validator.DoValidate(target, null, key, validationResults); Assert.IsFalse(validationResults.IsValid); ValidationResult validationResult = ValidationTestHelper.GetResultsList(validationResults)[0]; System.Text.RegularExpressions.Match match = TemplateStringTester.Match(validator.MessageTemplate, validationResult.Message); Assert.IsTrue(match.Success); Assert.IsTrue(match.Groups["param0"].Success); Assert.AreEqual(target.ToString(), match.Groups["param0"].Value); Assert.IsTrue(match.Groups["param1"].Success); Assert.AreEqual(key, match.Groups["param1"].Value); Assert.IsTrue(match.Groups["param2"].Success); Assert.AreEqual(validator.Tag, match.Groups["param2"].Value); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { RelativeDateTimeValidator validator = new RelativeDateTimeValidator(-10, DateTimeUnit.Day, 20, DateTimeUnit.Year, true); validator.Tag = "tag"; object target = DateTime.Now.AddDays(-2); 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.IsTrue(match.Groups["param3"].Success); Assert.AreEqual("-10", match.Groups["param3"].Value); Assert.IsTrue(match.Groups["param4"].Success); Assert.AreEqual("Day", match.Groups["param4"].Value); Assert.IsTrue(match.Groups["param5"].Success); Assert.AreEqual("20", match.Groups["param5"].Value); Assert.IsTrue(match.Groups["param6"].Success); Assert.AreEqual("Year", match.Groups["param6"].Value); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { RegexValidator validator = new RegexValidator("^[ab]+$", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace, true); validator.Tag = "tag"; object target = "ab"; 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.IsTrue(match.Groups["param3"].Success); Assert.AreEqual("^[ab]+$", match.Groups["param3"].Value); Assert.IsTrue(match.Groups["param4"].Success); Assert.AreEqual((RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace).ToString(), match.Groups["param4"].Value); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { StringLengthValidator validator = new StringLengthValidator(10, RangeBoundaryType.Exclusive, 20, RangeBoundaryType.Inclusive, true); validator.Tag = "tag"; object target = "not so short"; string key = "key"; ValidationResults validationResults = new ValidationResults(); validator.DoValidate(target, null, key, validationResults); Assert.IsFalse(validationResults.IsValid); ValidationResult validationResult = ValidationTestHelper.GetResultsList(validationResults)[0]; System.Text.RegularExpressions.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.IsTrue(match.Groups["param3"].Success); Assert.AreEqual("10", match.Groups["param3"].Value); Assert.IsTrue(match.Groups["param4"].Success); Assert.AreEqual("Exclusive", match.Groups["param4"].Value); Assert.IsTrue(match.Groups["param5"].Success); Assert.AreEqual("20", match.Groups["param5"].Value); Assert.IsTrue(match.Groups["param6"].Success); Assert.AreEqual("Inclusive", match.Groups["param6"].Value); }
public void SuppliesAppropriateParametersToMessageTemplate() { RelativeDateTimeValidator validator = new RelativeDateTimeValidator(-10, DateTimeUnit.Day, 20, DateTimeUnit.Year); validator.MessageTemplate = "{0}|{1}|{2}|{3}|{4}|{5}|{6}"; validator.Tag = "tag"; object target = DateTime.Now.AddDays(-20); string key = "key"; ValidationResults validationResults = new ValidationResults(); validator.DoValidate(target, null, key, validationResults); Assert.IsFalse(validationResults.IsValid); ValidationResult validationResult = ValidationTestHelper.GetResultsList(validationResults)[0]; System.Text.RegularExpressions.Match match = TemplateStringTester.Match(validator.MessageTemplate, validationResult.Message); Assert.IsTrue(match.Success); Assert.IsTrue(match.Groups["param0"].Success); Assert.AreEqual(target.ToString(), match.Groups["param0"].Value); Assert.IsTrue(match.Groups["param1"].Success); Assert.AreEqual(key, match.Groups["param1"].Value); Assert.IsTrue(match.Groups["param2"].Success); Assert.AreEqual(validator.Tag, match.Groups["param2"].Value); Assert.IsTrue(match.Groups["param3"].Success); Assert.AreEqual("-10", match.Groups["param3"].Value); Assert.IsTrue(match.Groups["param4"].Success); Assert.AreEqual("Day", match.Groups["param4"].Value); Assert.IsTrue(match.Groups["param5"].Success); Assert.AreEqual("20", match.Groups["param5"].Value); Assert.IsTrue(match.Groups["param6"].Success); Assert.AreEqual("Year", match.Groups["param6"].Value); }
public void SuppliesAppropriateParametersToMessageTemplate() { EnumConversionValidator validator = new EnumConversionValidator(typeof(MockEnumValidator)); validator.MessageTemplate = "{0}|{1}|{2}|{3}"; validator.Tag = "tag"; object target = "blah"; 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.IsTrue(match.Groups["param0"].Success); Assert.AreEqual(target, match.Groups["param0"].Value); Assert.IsTrue(match.Groups["param1"].Success); Assert.AreEqual(key, match.Groups["param1"].Value); Assert.IsTrue(match.Groups["param2"].Success); Assert.AreEqual(validator.Tag, match.Groups["param2"].Value); Assert.IsTrue(match.Groups["param3"].Success); Assert.AreEqual(typeof(MockEnumValidator).Name, match.Groups["param3"].Value); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { DomainValidator <int> validator = new DomainValidator <int>(true, 1, 2, 3, 4); validator.Tag = "tag"; object target = 1; 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); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { TypeConversionValidator validator = new TypeConversionValidator(typeof(int), true); validator.Tag = "tag"; object target = "10"; 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.IsTrue(match.Groups["param3"].Success); Assert.AreEqual("System.Int32", match.Groups["param3"].Value); }
public void SuppliesAppropriateParametersToDefaultNegatedMessage() { EnumConversionValidator validator = new EnumConversionValidator(typeof(MockEnumValidator), true); validator.Tag = "tag"; object target = MockEnumValidator.MyEnumValue.ToString(); string key = "key"; ValidationResults validationResults = new ValidationResults(); validator.DoValidate(target, null, key, validationResults); Assert.IsFalse(validationResults.IsValid); ValidationResult validationResult = ValidationTestHelper.GetResultsList(validationResults)[0]; System.Text.RegularExpressions.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.IsTrue(match.Groups["param3"].Success); Assert.AreEqual(typeof(MockEnumValidator).Name, match.Groups["param3"].Value); }