public void ValidatbleObjectAdapter()
        {
            var model = new TestModel();
            var k = new DataAnnotationsModelMetadataProvider();
            var metadata = k.GetMetadataForType(() => model, model.GetType());
            var controllerContext = new ControllerContext();
            var adapter = new MvcContrib.Localization.ValidatableObjectAdapter(metadata, controllerContext);

            var result = adapter.Validate(model).ToList();
            Assert.AreNotEqual(0, result.Count);
        }
Exemplo n.º 2
0
        public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms)
        {
            var htmlHelperOption = context.tryfind("Html");
            if (htmlHelperOption == null)
                return "";

            var htmlHelper = (HtmlHelper)htmlHelperOption.Value;

            var metadata_provider = new DataAnnotationsModelMetadataProvider();

            if (context.ModelType == null)
                htmlHelper.ViewData.ModelMetadata = null;
            else
            {
                var model = Activator.CreateInstance(context.ModelType.Value);
                htmlHelper.ViewData.ModelMetadata = metadata_provider.GetMetadataForType(() => model, context.ModelType.Value);
            }

            var result = htmlHelper.Label(parms[0].ToString());
            if (result == null)
                return "";
            else
                return result.ToHtmlString();
        }
 private static ModelMetadata GetMetadataForType(Type t)
 {
     DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
     return metadataProvider.GetMetadataForType(null, t);
 }
 private static ModelMetadata GetMetadataForObject(object o)
 {
     DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
     return metadataProvider.GetMetadataForType(() => o, o.GetType());
 }
        public void ClientValidatable()
        {
            ValidationMessageProviders.Reset();
            var model = new TestModel();
            var k = new DataAnnotationsModelMetadataProvider();
            var metadata = k.GetMetadataForType(() => model, model.GetType());
            var validators = _provider.GetValidators(metadata, new ControllerContext());

            var result = validators.ToList().First().Validate(model).ToList();

            Assert.NotEqual(0, result.Count);

        }