Ejemplo n.º 1
0
 public ActionResult Index()
 {
     Dictionary<string, ModelValidator[]> modelValidators = new Dictionary<string, ModelValidator[]>();
     DataAnnotationsModelValidatorProvider validatorProvider = new DataAnnotationsModelValidatorProvider();
     foreach (ModelMetadata metadata in ModelMetadataProviders.Current.GetMetadataForProperties(new DemoModel(), typeof(DemoModel)))
     {
         modelValidators.Add(metadata.PropertyName, validatorProvider.GetValidators(metadata, this.ControllerContext).ToArray());
     }
     return View(modelValidators);
 }
        public void RegisterAdapters_RegistersAdapter(String property, Type adapterType)
        {
            DataAnnotationsModelValidatorProvider provider = new DataAnnotationsModelValidatorProvider();
            ModelMetadata metadata = new DataAnnotationsModelMetadataProvider()
                .GetMetadataForProperty(null, typeof(AdaptersModel), property);

            application.RegisterAdapters();

            ModelValidator adapter = provider
                .GetValidators(metadata, new ControllerContext())
                .SingleOrDefault(validator => validator.GetType() == adapterType);

            Assert.NotNull(adapter);
        }
Ejemplo n.º 3
0
 static UniqueStringAttribute()
 {
     DataAnnotationsModelValidatorProvider.RegisterAdapterFactory(typeof(UniqueStringAttribute), new DataAnnotationsModelValidationFactory(UniqueStringAttribute.Create));
 }