public ValidationHtmlConvention(IFieldValidationQuery fieldValidationQuery,
                                 HtmlConventionRegistry htmlConvention,
                                 IEnumerable<IHtmlValidationConvention> conventions)
 {
     _fieldValidationQuery = fieldValidationQuery;
     _htmlConvention = htmlConvention;
     _conventions = conventions;
 }
        public void fill_service_with_nothing_should_add_the_service()
        {
            var registry1 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();
            services.SetServiceIfNone(registry1);

            services.FindAllValues<HtmlConventionRegistry>().ShouldHaveTheSameElementsAs(registry1);
        }
        public void fill_service_that_has_something_already_does_not_add_values()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();
            services.AddService(registry1);

            services.SetServiceIfNone(registry2);

            services.FindAllValues<HtmlConventionRegistry>().ShouldHaveTheSameElementsAs(registry1);
        }
Beispiel #4
0
        public void SetUp()
        {
            theTarget = new ConventionTarget();
            theRegistry = new HtmlConventionRegistry();
            _generator = new Lazy<IElementGenerator<ConventionTarget>>(() =>
            {
                return HtmlElementScenario<ConventionTarget>.For(x =>
                {
                    x.Library.Import(theRegistry.Library);
                    x.Model = theTarget;
                });
            });


        }
        public void ClearAll()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();
            var registry3 = new HtmlConventionRegistry();
            var registry4 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();
            services.AddService(registry1);
            services.AddService(registry2);
            services.AddService(registry3);
            services.AddService(registry4);

            services.ClearAll<HtmlConventionRegistry>();

            services.FindAllValues<HtmlConventionRegistry>().Any().ShouldBeFalse();
        }
        public void GetAllValues()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();
            var registry3 = new HtmlConventionRegistry();
            var registry4 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();
            services.AddService(registry1);
            services.AddService(registry2);
            services.AddService(registry3);
            services.AddService(registry4);

            services.AddService<HtmlConventionRegistry, HtmlConventionRegistry>();

            services.FindAllValues<HtmlConventionRegistry>()
                .ShouldHaveTheSameElementsAs(registry1, registry2, registry3, registry4);
        }
        public void should_add_object_def_directly()
        {
            var registry1 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();
            var objectDef = new ObjectDef(typeof (HtmlConventionRegistry)){
                Value = registry1
            };
            services.AddService(typeof (HtmlConventionRegistry), objectDef);

            services.ToGraph().DefaultServiceFor<HtmlConventionRegistry>().ShouldEqual(objectDef);
        }
        public CoreRegistry()
        {
            Applies.ToThisAssembly();
            //IncludeDiagnostics(true);

            Actions.IncludeTypesNamed(x => x.EndsWith("Handler"));

            Routes
                .ConstrainToHttpMethod(x => x.Method.Name.EndsWith("Query"), "GET")
                .ConstrainToHttpMethod(x => x.Method.Name.EndsWith("Command"), "POST");

            Routes
                .IgnoreNamespaceText(typeof(CoreRegistry).Namespace)
                .IgnoreNamespaceText("Handlers")
                .IgnoreMethodsNamed("Query")
                .IgnoreMethodsNamed("Command")
                .IgnoreClassSuffix("Handler");

            Routes.HomeIs<HomeHandler>(x => x.Query(new HomeQueryModel()));
            Views.TryToAttachWithDefaultConventions()
                .RegisterActionLessViews(t => t.ViewModelType == typeof(Notification));

            this.UseSpark();

            Policies.ConditionallyWrapBehaviorChainsWith<HandlerAssetConvention>(x => x.HandlerType.Namespace.Contains("Products"));

            Policies.Add(new ProductNotFoundPolicy<EditHandler>(h => h.Query(null)));
            Policies.Add(new ProductNotFoundPolicy<DeleteHandler>(h => h.Query(null)));

            Output.ToJson.WhenCallMatches(x => x.Method.Name.Equals("Data"));

            Import<BasicLocalizationSupport>(x =>
            {
                x.LocalizationStorageIs<InMemoryLocalizationStorage>();
                x.LoadLocalizationWith<LocalizationActivator>();
                x.DefaultCulture = Thread.CurrentThread.CurrentUICulture;
            });

            var validationRulesHtmlConventionActivator = ObjectDef.ForType<ValidationHtmlConvention>();
            var validationRulesHtmlConvention = new HtmlConventionRegistry();
            validationRulesHtmlConventionActivator.DependencyByValue(validationRulesHtmlConvention);

            Services(cfg =>
                         {
                             cfg.SetServiceIfNone<IProductService, InMemoryProductService>();
                             cfg.SetServiceIfNone(Mapper.Engine);
                             cfg.SetServiceIfNone(Mapper.Configuration);
                             cfg.SetServiceIfNone<ILocaleCacheFactory, LocaleCacheFactory>();
                             cfg.SetServiceIfNone<IValidationDescriptorProvider>(new ValidationDescriptorProvider());
                             cfg.AddService<IHtmlValidationConvention, LocalizedNameConvention>();
                             cfg.AddService<IHtmlValidationConvention, RequiredHtmlValidationConvention>();
                             cfg.AddService<IHtmlValidationConvention, GreaterOrEqualToZeroHtmlValidationConvention>();
                             cfg.AddService<IHtmlValidationConvention, MaximumLengthHtmlValidationConvention>();
                             cfg.AddService<IFieldValidationSource, AddProductModelValidationSource>();
                             cfg.AddService<IActivator, AutoMapperActivator>();
                             cfg.AddService<IActivator, ValidationDescriptorProviderFiller>();
                             cfg.AddService(typeof (IActivator), validationRulesHtmlConventionActivator);
                         });

            HtmlConvention(htmlConventions);
            HtmlConvention(validationRulesHtmlConvention);

            this.Validation(validation =>
            {
                validation.Actions.Include(call => call.HasInput && call.Method.Name.Equals("Command"));
                validation.Failures
                    .IfModelIs<EditProductCommandModel>().TransferBy<ValidationDescriptor>();
            });

            Models.BindPropertiesWith<OriginalModelBinder>();
        }
        private static void htmlConventions(HtmlConventionRegistry x)
        {
            x.Editors
                .Always
                .Modify((e, tag) => tag.Attr("placeholder", e.Accessor.Name));

            x.Editors
                .If(p => p.Accessor.InnerProperty.Name.Equals("Description"))
                .Modify((e, tag) => tag.TagName("textarea").RemoveAttr("value").Text(e.Value<string>()));

            x.Editors
                .If(p => p.Accessor.InnerProperty.Name.Equals("Quantity"))
                .Modify((e, tag) => tag.AddClass("mini"));
        }