/// <summary> /// Probably only useful for testing /// </summary> /// <param name="library"></param> /// <param name="activators"></param> /// <returns></returns> public static ElementGenerator <T> For(HtmlConventionLibrary library, IEnumerable <ITagRequestActivator> activators = null) { var tags = new TagGenerator <ElementRequest>(library.For <ElementRequest>(), new TagRequestBuilder(activators ?? new ITagRequestActivator[0]), new ActiveProfile()); return(new ElementGenerator <T>(tags, new InMemoryFubuRequest())); }
public void if_not_explicitly_specified_assume_the_profile_is_default() { var library = new HtmlConventionLibrary(); library.RegisterService<IFoo, Foo>(TagConstants.Default); library.Get<IFoo>().ShouldBeOfType<Foo>(); }
public void fetching_by_profile_should_fall_back_to_default_if_not_specific_implementation_is_used() { var library = new HtmlConventionLibrary(); library.RegisterService<IFoo, Foo>(TagConstants.Default); library.Get<IFoo>("Profile1").ShouldBeOfType<Foo>(); }
public TemplateWriter(ActiveProfile profile, HtmlConventionLibrary library, ITagRequestBuilder tagRequestBuilder) { _library = library; var factory = new TagGeneratorFactory(profile, library, tagRequestBuilder); _elements = new Lazy <ITagGenerator <ElementRequest> >(factory.GeneratorFor <ElementRequest>); }
public HtmlTagRegistry() { var htmlConventionLibrary = new HtmlConventionLibrary(); new DefaultAspNetMvcHtmlConventions().Apply(htmlConventionLibrary); new DefaultHtmlConventions().Apply(htmlConventionLibrary); For<HtmlConventionLibrary>().Use(htmlConventionLibrary); }
public void importing_test() { var b1 = MockRepository.GenerateMock <ITagBuilder <FakeSubject> >(); var b2 = MockRepository.GenerateMock <ITagBuilder <FakeSubject> >(); var b3 = MockRepository.GenerateMock <ITagBuilder <FakeSubject> >(); var b4 = MockRepository.GenerateMock <ITagBuilder <SecondSubject> >(); var b5 = MockRepository.GenerateMock <ITagBuilder <SecondSubject> >(); var b6 = MockRepository.GenerateMock <ITagBuilder <SecondSubject> >(); var lib1 = new HtmlConventionLibrary(); lib1.For <FakeSubject>().Add(b1); lib1.For <FakeSubject>().Add(b2); var lib2 = new HtmlConventionLibrary(); lib2.For <FakeSubject>().Add(b3); lib2.For <SecondSubject>().Add(b4); lib2.For <SecondSubject>().Add(b5); lib2.For <SecondSubject>().Add(b6); lib1.Import(lib2); lib1.For <FakeSubject>().Default.Defaults.Builders.ShouldHaveTheSameElementsAs(b1, b2, b3); lib1.For <SecondSubject>().Default.Defaults.Builders.ShouldHaveTheSameElementsAs(b4, b5, b6); }
public void importing_test() { var b1 = new Mock <ITagBuilderPolicy>().Object; var b2 = new Mock <ITagBuilderPolicy>().Object; var b3 = new Mock <ITagBuilderPolicy>().Object; var b4 = new Mock <ITagBuilderPolicy>().Object; var b5 = new Mock <ITagBuilderPolicy>().Object; var b6 = new Mock <ITagBuilderPolicy>().Object; var lib1 = new HtmlConventionLibrary(); lib1.TagLibrary.Add(b1); lib1.TagLibrary.Add(b2); var lib2 = new HtmlConventionLibrary(); lib2.TagLibrary.Add(b3); lib2.TagLibrary.Add(b4); lib2.TagLibrary.Add(b5); lib2.TagLibrary.Add(b6); lib1.Import(lib2); lib1.TagLibrary.Default.Defaults.Policies.ShouldHaveTheSameElementsAs(b1, b2, b3, b4, b5, b6); }
public void simple_registration_of_service_by_type() { var library = new HtmlConventionLibrary(); library.RegisterService <IFoo, Foo>(); library.Get <IFoo>().ShouldBeOfType <Foo>(); }
public void if_not_explicitly_specified_assume_the_profile_is_default() { var library = new HtmlConventionLibrary(); library.RegisterService <IFoo, Foo>(TagConstants.Default); library.Get <IFoo>().ShouldBeOfType <Foo>(); }
public void fetching_by_profile_should_fall_back_to_default_if_not_specific_implementation_is_used() { var library = new HtmlConventionLibrary(); library.RegisterService <IFoo, Foo>(TagConstants.Default); library.Get <IFoo>("Profile1").ShouldBeOfType <Foo>(); }
public HtmlTagRegistry() { var htmlConventionLibrary = new HtmlConventionLibrary(); new DefaultAspNetMvcHtmlConventions().Apply(htmlConventionLibrary); new DefaultHtmlConventions().Apply(htmlConventionLibrary); For <HtmlConventionLibrary>().Use(htmlConventionLibrary); }
public FormLineExpressionBuilder(IElementGenerator <T> generator, HtmlConventionLibrary library, ActiveProfile profile, IFieldAccessService fieldAccessService, IFubuRequest request) { _generator = generator; _library = library; _profile = profile; _fieldAccessService = fieldAccessService; _request = request; }
public static HtmlConventionLibrary CreateHtmlConventionLibrary() { var htmlConventionLibrary = new HtmlConventionLibrary(); new OdsAdminHtmlTagConventions().Apply(htmlConventionLibrary); new DefaultHtmlConventions().Apply(htmlConventionLibrary); return(htmlConventionLibrary); }
public static void BuildHtmlConventionLibrary(HtmlConventionLibrary library, AccessorRules rules) { library.Import(new DefaultHtmlConventions().Library); var visitor = new Visitor(rules); library.For <ElementRequest>().AcceptVisitor(visitor); }
public static void AddHtmlTags(this IServiceCollection services, params HtmlConventionRegistry[] registries) { var library = new HtmlConventionLibrary(); foreach (var registry in registries) { registry.Apply(library); } services.AddHtmlTags(library); }
public static void AddHtmlTags(this IServiceCollection services, params HtmlConventionRegistry[] registries) { var library = new HtmlConventionLibrary(); foreach (var registry in registries) { registry.Apply(library); } services.AddHtmlTags(library); }
public void for_returns_the_same_result() { var library = new HtmlConventionLibrary(); var lib1 = library.For<FakeSubject>(); var lib2 = library.For<FakeSubject>(); lib1.ShouldBeTheSameAs(lib2); library.For<SecondSubject>().ShouldBeTheSameAs(library.For<SecondSubject>()); }
public void register_and_build_by_profile() { var library = new HtmlConventionLibrary(); library.RegisterService <IFoo, Foo>(TagConstants.Default); library.RegisterService <IFoo, DifferentFoo>("Profile1"); library.Get <IFoo>("Profile1").ShouldBeOfType <DifferentFoo>(); }
public void registration_of_service_by_func() { var library = new HtmlConventionLibrary(); library.RegisterService <IFoo>(() => new ColoredFoo { Color = "Red" }); library.Get <IFoo>().ShouldBeOfType <ColoredFoo>() .Color.ShouldEqual("Red"); }
public void for_returns_the_same_result() { var library = new HtmlConventionLibrary(); var lib1 = library.For <FakeSubject>(); var lib2 = library.For <FakeSubject>(); lib1.ShouldBeTheSameAs(lib2); library.For <SecondSubject>().ShouldBeTheSameAs(library.For <SecondSubject>()); }
public void Test() { var library = new HtmlConventionLibrary(); new DefaultHtmlConventions().Apply(library); var generator = ElementGenerator <Foo> .For(library); var tag = generator.InputFor(m => m.Value); tag = generator.InputFor(m => m.Value); }
public void services_are_not_overwritten_while_importing() { var library1 = new HtmlConventionLibrary(); library1.RegisterService<IFoo, LittleFoo>(); var library2 = new HtmlConventionLibrary(); library2.RegisterService<IFoo, BigFoo>(); library1.Import(library2); library1.Get<IFoo>().ShouldBeType<LittleFoo>(); }
public void services_are_imported() { var library1 = new HtmlConventionLibrary(); library1.RegisterService<IFoo, LittleFoo>(); var library2 = new HtmlConventionLibrary(); library2.RegisterService<IFoo, BigFoo>("different"); library1.Import(library2); library1.Get<IFoo>().ShouldBeType<LittleFoo>(); library1.Get<IFoo>("different").ShouldBeType<BigFoo>(); }
public void services_are_not_overwritten_while_importing() { var library1 = new HtmlConventionLibrary(); library1.RegisterService <IFoo, LittleFoo>(); var library2 = new HtmlConventionLibrary(); library2.RegisterService <IFoo, BigFoo>(); library1.Import(library2); library1.Get <IFoo>().ShouldBeOfType <LittleFoo>(); }
public void services_are_imported() { var library1 = new HtmlConventionLibrary(); library1.RegisterService <IFoo, LittleFoo>(); var library2 = new HtmlConventionLibrary(); library2.RegisterService <IFoo, BigFoo>("different"); library1.Import(library2); library1.Get <IFoo>().ShouldBeOfType <LittleFoo>(); library1.Get <IFoo>("different").ShouldBeOfType <BigFoo>(); }
protected override void beforeEach() { theActivators = Services.CreateMockArrayFor <ITagRequestActivator>(5); theActivators[0].Stub(x => x.Matches(typeof(FakeSubject))).Return(true); theActivators[1].Stub(x => x.Matches(typeof(FakeSubject))).Return(false); theActivators[2].Stub(x => x.Matches(typeof(FakeSubject))).Return(true); theActivators[3].Stub(x => x.Matches(typeof(FakeSubject))).Return(false); theActivators[4].Stub(x => x.Matches(typeof(FakeSubject))).Return(true); theLibrary = new HtmlConventionLibrary(); Services.Inject(theLibrary); }
/// <summary> /// Configures HtmlTags with ASP.NET Core defaults /// </summary> /// <param name="services">Service collection</param> /// <param name="registries">Custom convention registries</param> /// <returns>Service collection</returns> public static IServiceCollection AddHtmlTags(this IServiceCollection services, params HtmlConventionRegistry[] registries) { var library = new HtmlConventionLibrary(); var defaultRegistry = new HtmlConventionRegistry() .Defaults() .ModelMetadata() .ModelState(); defaultRegistry.Apply(library); foreach (var registry in registries) { registry.Apply(library); } return(services.AddHtmlTags(library)); }
public static IServiceCollection AddMiruHtml(this IServiceCollection services, params HtmlConventionRegistry[] registries) { services.AddSingleton <HtmlGenerator>(); services.AddSingleton <ElementNaming>(); services.AddSingleton <IElementNamingConvention, DotNotationElementNamingConvention>(); services.AddSingleton <HtmlGenerator, HtmlGenerator>(); services.AddTransient <IAntiforgeryAccessor, AntiForgeryAccessor>(); var library = new HtmlConventionLibrary(); var defaultRegistry = new HtmlConventionRegistry() .DefaultModifiers(); defaultRegistry.Apply(library); if (registries.Length > 0) { foreach (var registry in registries) { registry.Apply(library); } } else { new HtmlConfiguration().Apply(library); } var defaultBuilders = new HtmlConventionRegistry(); // defaultBuilders.Editors.BuilderPolicy<CheckboxBuilder>(); defaultBuilders.Editors.Always.BuildBy <TextboxBuilder>(); defaultBuilders.Labels.Always.BuildBy <DefaultLabelBuilder>(); defaultBuilders.DefaultNamingConvention(); defaultBuilders.Displays.Always.BuildBy <SpanDisplayBuilder>(); defaultBuilders.Displays.NamingConvention(new DotNotationElementNamingConvention()); defaultBuilders.Apply(library); return(services.AddHtmlTags(library)); }
public AspNetMvcFubuRegistry(params HtmlConventionRegistry[] registries) { var htmlConventionLibrary = new HtmlConventionLibrary(); registries.Select(r => r.Library).Each(library => htmlConventionLibrary.Import(library)); htmlConventionLibrary.Import(new DefaultAspNetMvcHtmlConventions().Library); htmlConventionLibrary.Import(new DefaultHtmlConventions().Library); For <HtmlConventionLibrary>().Use(htmlConventionLibrary); Scan(x => { x.AssemblyContainingType <IFubuRequest>(); x.AssemblyContainingType <ITypeResolver>(); x.AssemblyContainingType <ITagGeneratorFactory>(); x.AssemblyContainingType <FubuMVC.StructureMap.StructureMapFubuRegistry>(); x.WithDefaultConventions(); x.LookForRegistries(); }); For <IValueSource>().AddInstances(c => { c.Type <RequestPropertyValueSource>(); }); For <ITagRequestActivator>().AddInstances(c => { c.Type <ElementRequestActivator>(); c.Type <ServiceLocatorTagRequestActivator>(); }); For <HttpRequestBase>().Use(c => c.GetInstance <HttpRequestWrapper>()); For <ITypeResolverStrategy>().Use <TypeResolver.DefaultStrategy>(); //For<IElementNamingConvention>().Use<AspNetMvcElementNamingConvention>(); For <IElementNamingConvention>().Use <DefaultElementNamingConvention>(); For(typeof(ITagGenerator <>)).Use(typeof(TagGenerator <>)); For(typeof(IElementGenerator <>)).Use(typeof(ElementGenerator <>)); For <IServiceLocator>().Use(() => ServiceLocator.Current); For <ITemplateWriter>().Use <TemplateWriter>(); }
public void importing_test() { var b1 = new Mock<ITagBuilderPolicy>().Object; var b2 = new Mock<ITagBuilderPolicy>().Object; var b3 = new Mock<ITagBuilderPolicy>().Object; var b4 = new Mock<ITagBuilderPolicy>().Object; var b5 = new Mock<ITagBuilderPolicy>().Object; var b6 = new Mock<ITagBuilderPolicy>().Object; var lib1 = new HtmlConventionLibrary(); lib1.TagLibrary.Add(b1); lib1.TagLibrary.Add(b2); var lib2 = new HtmlConventionLibrary(); lib2.TagLibrary.Add(b3); lib2.TagLibrary.Add(b4); lib2.TagLibrary.Add(b5); lib2.TagLibrary.Add(b6); lib1.Import(lib2); lib1.TagLibrary.Default.Defaults.Policies.ShouldHaveTheSameElementsAs(b1, b2, b3, b4, b5, b6); }
public AspNetMvcFubuRegistry(params HtmlConventionRegistry[] registries) { var htmlConventionLibrary = new HtmlConventionLibrary(); registries.Select(r => r.Library).Each(library => htmlConventionLibrary.Import(library)); htmlConventionLibrary.Import(new DefaultAspNetMvcHtmlConventions().Library); htmlConventionLibrary.Import(new DefaultHtmlConventions().Library); For<HtmlConventionLibrary>().Use(htmlConventionLibrary); Scan(x => { x.AssemblyContainingType<IFubuRequest>(); x.AssemblyContainingType<ITypeResolver>(); x.AssemblyContainingType<ITagGeneratorFactory>(); x.AssemblyContainingType<FubuMVC.StructureMap.StructureMapFubuRegistry>(); x.WithDefaultConventions(); x.LookForRegistries(); }); For<IValueSource>().AddInstances(c => { c.Type<RequestPropertyValueSource>(); }); For<ITagRequestActivator>().AddInstances(c => { c.Type<ElementRequestActivator>(); c.Type<ServiceLocatorTagRequestActivator>(); }); For<HttpRequestBase>().Use(c => c.GetInstance<HttpRequestWrapper>()); For<ITypeResolverStrategy>().Use<TypeResolver.DefaultStrategy>(); //For<IElementNamingConvention>().Use<AspNetMvcElementNamingConvention>(); For<IElementNamingConvention>().Use<DefaultElementNamingConvention>(); For(typeof(ITagGenerator<>)).Use(typeof(TagGenerator<>)); For(typeof(IElementGenerator<>)).Use(typeof(ElementGenerator<>)); For<IServiceLocator>().Use(() => ServiceLocator.Current); For<ITemplateWriter>().Use<TemplateWriter>(); }
public ProfileExpression(HtmlConventionLibrary library, string profileName) { _library = library; _profileName = profileName; }
public static void AddHtmlTags(this IServiceCollection services, HtmlConventionLibrary library) { services.AddSingleton(library); }
public ProfileExpression(HtmlConventionLibrary library, string profileName) { Library = library; _profileName = profileName; }
public void Apply(HtmlConventionLibrary library) { library.Import(Library); }
private HtmlConventionRegistry(HtmlConventionLibrary library) : base(library, TagConstants.Default) { _library = library; _templates = new Lazy <ProfileExpression>(() => new ProfileExpression(_library, ElementConstants.Templates)); }
public static void AddHtmlTags(this IServiceCollection services, HtmlConventionLibrary library) { services.AddSingleton(library); }
public HtmlConventionSettings() { ConventionLibrary = new HtmlConventionLibrary(); _profileExpression = new ProfileExpression(ConventionLibrary, TagConstants.Default); }
private HtmlTagsConfiguration() { Conventions = new HtmlConventionLibrary(); DefaultFormBlockBuilderFactory = () => new DefaultFormBlockBuilder(); }
public void importing_test() { var b1 = MockRepository.GenerateMock<ITagBuilderPolicy<FakeSubject>>(); var b2 = MockRepository.GenerateMock<ITagBuilderPolicy<FakeSubject>>(); var b3 = MockRepository.GenerateMock<ITagBuilderPolicy<FakeSubject>>(); var b4 = MockRepository.GenerateMock<ITagBuilderPolicy<SecondSubject>>(); var b5 = MockRepository.GenerateMock<ITagBuilderPolicy<SecondSubject>>(); var b6 = MockRepository.GenerateMock<ITagBuilderPolicy<SecondSubject>>(); var lib1 = new HtmlConventionLibrary(); lib1.For<FakeSubject>().Add(b1); lib1.For<FakeSubject>().Add(b2); var lib2 = new HtmlConventionLibrary(); lib2.For<FakeSubject>().Add(b3); lib2.For<SecondSubject>().Add(b4); lib2.For<SecondSubject>().Add(b5); lib2.For<SecondSubject>().Add(b6); lib1.Import(lib2); lib1.For<FakeSubject>().Default.Defaults.Policies.ShouldHaveTheSameElementsAs(b1, b2, b3); lib1.For<SecondSubject>().Default.Defaults.Policies.ShouldHaveTheSameElementsAs(b4, b5, b6); }
public void Import(HtmlConventionLibrary target, HtmlConventionLibrary source) { target.For <T>().Import(source.For <T>()); }
public void registration_of_service_by_func() { var library = new HtmlConventionLibrary(); library.RegisterService<IFoo>(() => new ColoredFoo{Color = "Red"}); library.Get<IFoo>().ShouldBeType<ColoredFoo>() .Color.ShouldEqual("Red"); }
public void register_and_build_by_profile() { var library = new HtmlConventionLibrary(); library.RegisterService<IFoo, Foo>(TagConstants.Default); library.RegisterService<IFoo, DifferentFoo>("Profile1"); library.Get<IFoo>("Profile1").ShouldBeType<DifferentFoo>(); }
public static HtmlConventionLibrary AddConvention(this HtmlConventionLibrary library, HtmlConventionRegistry convention) { convention.Apply(library); return(library); }
public void simple_registration_of_service_by_type() { var library = new HtmlConventionLibrary(); library.RegisterService<IFoo, Foo>(); library.Get<IFoo>().ShouldBeType<Foo>(); }