Ejemplo n.º 1
0
 public void SetUp()
 {
     mockFactory         = new MockMemberAccessValidatorBuilderFactory();
     configurationSource = new DictionaryConfigurationSource();
     builder             =
         ConfigurationValidatorBuilder.FromConfiguration(
             configurationSource,
             mockFactory,
             ValidationFactory.DefaultCompositeValidatorFactory);
 }
 public void SetUp()
 {
     mockFactory = new MockMemberAccessValidatorBuilderFactory();
     configurationSource = new DictionaryConfigurationSource();
     builder =
         ConfigurationValidatorBuilder.FromConfiguration(
             configurationSource,
             mockFactory,
             ValidationFactory.DefaultCompositeValidatorFactory);
 }
 public void TestInitialize()
 {
     ValidationFactory.SetDefaultConfigurationValidatorFactory(new SystemConfigurationSource(false));
     mockFactory         = new MockMemberAccessValidatorBuilderFactory();
     configurationSource = new DictionaryConfigurationSource();
     builder             =
         ConfigurationValidatorBuilder.FromConfiguration(
             configurationSource,
             mockFactory,
             ValidationFactory.DefaultCompositeValidatorFactory);
 }
Ejemplo n.º 4
0
        public void CanCreateValidatorForTypeWithMultipleValidationConfigurationWithProvidedRulesetThroughTopLevelFactoryMethod()
        {
            ValidationSettings settings = new ValidationSettings();

            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(TestClass));

            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleB";
            ValidationRulesetData ruleDataA = new ValidationRulesetData("RuleA");

            typeReference.Rulesets.Add(ruleDataA);
            ruleDataA.Validators.Add(new MockValidatorData("validator1", false));
            ruleDataA.Validators.Get("validator1").MessageTemplate = "Message1-RuleA";
            ruleDataA.Validators.Add(new MockValidatorData("validator2", false));
            ruleDataA.Validators.Get("validator2").MessageTemplate = "Message2-RuleA";
            ruleDataA.Validators.Add(new MockValidatorData("validator3", false));
            ruleDataA.Validators.Get("validator3").MessageTemplate = "Message3-RuleA";
            ValidationRulesetData ruleDataB = new ValidationRulesetData("RuleB");

            typeReference.Rulesets.Add(ruleDataB);
            ruleDataB.Validators.Add(new MockValidatorData("validator1", false));
            ruleDataB.Validators.Get("validator1").MessageTemplate = "Message1-RuleB";
            ruleDataB.Validators.Add(new MockValidatorData("validator2", false));
            ruleDataB.Validators.Get("validator2").MessageTemplate = "Message1-RuleB";

            // Note: Use a local builder here since the assumption was made about how and when the
            //       the builder uses the configuration source....
            var localBuilder =
                ConfigurationValidatorBuilder.FromConfiguration(
                    configurationSource,
                    mockFactory,
                    ValidationFactory.DefaultCompositeValidatorFactory);
            Validator validator = localBuilder.CreateValidator(typeof(TestClass), "RuleA");

            Assert.IsNotNull(validator);
            CompositeValidatorBuilder compositeValidatorBuilder = mockFactory.requestedTypes["TestClass"];

            Assert.IsNotNull(compositeValidatorBuilder);
            Assert.AreEqual(false, compositeValidatorBuilder.IgnoreNulls);
            Assert.AreEqual(CompositionType.And, compositeValidatorBuilder.CompositionType);
            IDictionary <string, MockValidator <object> > valueValidators = ValidationTestHelper.CreateMockValidatorsMapping(compositeValidatorBuilder.ValueValidators);

            Assert.AreEqual(3, valueValidators.Count);
            Assert.IsTrue(valueValidators.ContainsKey("Message1-RuleA"));
            Assert.IsTrue(valueValidators.ContainsKey("Message2-RuleA"));
            Assert.IsTrue(valueValidators.ContainsKey("Message3-RuleA"));
        }
Ejemplo n.º 5
0
        public void CreateValidatorForDefaultPropertyForExistingTypeInConfigurationRetunsAppropriateValidatorBasedOnRule()
        {
            ValidationSettings settings = new ValidationSettings();

            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(TestClass));

            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "ruleset1";
            ValidationRulesetData ruleData = new ValidationRulesetData("ruleset1");

            typeReference.Rulesets.Add(ruleData);
            ValidatedMethodReference methodReference1 = new ValidatedMethodReference("PublicMethod");

            ruleData.Methods.Add(methodReference1);
            ValidatedMethodReference methodReference2 = new ValidatedMethodReference("NonPublicMethod");

            ruleData.Methods.Add(methodReference2);
            methodReference1.Validators.Add(new MockValidatorData("validator1", false));
            methodReference1.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            methodReference2.Validators.Add(new MockValidatorData("validator2", false));
            methodReference2.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            // Note: Use a local builder here since the assumption was made about how and when the
            //       the builder uses the configuration source....
            var localBuilder =
                ConfigurationValidatorBuilder.FromConfiguration(
                    configurationSource,
                    mockFactory,
                    ValidationFactory.DefaultCompositeValidatorFactory);
            Validator validator = localBuilder.CreateValidator(typeof(TestClass), string.Empty);

            Assert.IsNotNull(validator);
            Assert.AreSame(typeof(ValueAccessValidator), validator.GetType());
            ValueAccessValidatorBuilder valueAccessValidatorBuilder1 = mockFactory.requestedMembers["TestClass.PublicMethod"];

            Assert.AreSame(valueAccessValidatorBuilder1.BuiltValidator, validator);
            Assert.AreEqual("validator 1 message", ((MockValidator <object>)valueAccessValidatorBuilder1.ValueValidators[0]).MessageTemplate);
        }
Ejemplo n.º 6
0
 public void SetUp()
 {
     this.mockFactory         = new MockMemberAccessValidatorBuilderFactory();
     this.configurationSource = new DictionaryConfigurationSource();
     this.builder             = new ConfigurationValidatorBuilder(this.configurationSource, this.mockFactory);
 }