protected override void beforeEach() { _context = ObjectMother.BasicPreviewContext(); _model = new HtmlConventionsPreviewViewModel(); Container .Configure(x => { x.For <IServiceLocator>().Use(() => new StructureMapServiceLocator(Container)); }); MockFor <ITagGeneratorFactory>() .Expect(f => f.GeneratorFor(_context.ModelType)) .Return(MockFor <ITagGenerator <SampleContextModel> >()); MockFor <ITagGenerator <SampleContextModel> >() .Expect(t => t.GetRequest(Arg <Accessor> .Is.Anything)) .Return(new ElementRequest(_context.Instance, ReflectionHelper.GetAccessor <SampleContextModel>(m => m.Public), MockFor <IServiceLocator>())) .Repeat .Any(); MockFor <ITagGenerator <SampleContextModel> >() .Expect(t => t.LabelFor(Arg <ElementRequest> .Is.Anything)) .Return(new HtmlTag("label")); MockFor <ITagGenerator <SampleContextModel> >() .Expect(t => t.InputFor(Arg <ElementRequest> .Is.Anything)) .Return(new HtmlTag("input")); MockFor <ITagGenerator <SampleContextModel> >() .Expect(t => t.DisplayFor(Arg <ElementRequest> .Is.Anything)) .Return(new HtmlTag("span")); }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var links = new List <PropertyLink>(); context .NonConvertibleProperties() .Each(prop => { var path = "{0}-{1}".ToFormat(context.Path, prop.Name); var type = prop.PropertyType; if (type.IsInterface || type.IsAbstract || type.IsGenericType || type.GetConstructor(new Type[0]) == null) { path = ""; } links.Add(new PropertyLink { Path = path, Source = _sourceGenerator.SourceFor(prop) }); }); model.Links = links; }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var path = context.ModelType.FullName; if(context.PropertyChain.Any()) { path = "{0}.{1}".ToFormat(path, context.PropertyChain.Select(p => p.Name).Join(".")); } model.Type = path; }
public void should_build_property_paths_with_periods() { var prop = ReflectionHelper.GetProperty <SampleContextModel>(m => m.Child); var context = new HtmlConventionsPreviewContext(typeof(SampleContextModel).FullName, typeof(SampleContextModel), new SampleContextModel(), new PropertyInfo[] { prop }); _builder.Enrich(context, _model); _model .Type .ShouldEqual("{0}.{1}".ToFormat(context.ModelType.FullName, prop.Name)); }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var path = context.ModelType.FullName; if (context.PropertyChain.Any()) { path = "{0}.{1}".ToFormat(path, context.PropertyChain.Select(p => p.Name).Join(".")); } model.Type = path; model.Namespace = context.ModelType.Namespace; model.Assembly = context.ModelType.Assembly.GetName().Name; }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var examples = new List<PropertyExample>(); var tagGenerator = _generatorFactory.GeneratorFor(context.ModelType); tagGenerator.SetModel(context.Instance); _populator.PopulateInstance(context.Instance, context.SimpleProperties()); context .SimpleProperties() .Each(prop => { Accessor property; if(context.PropertyChain.Any()) { property = new PropertyChain(context .PropertyChain .Concat<PropertyInfo>(new[] {prop}) .Select(x => new PropertyValueGetter(x)) .ToArray()); } else { property = new SingleProperty(prop); } var propertyExpression = "x => x." + property.PropertyNames.Join("."); var propertySource = _sourceGenerator.SourceFor(prop); var propExamples = new List<Example>(); propExamples.Add(createExample(tagGenerator.LabelFor(tagGenerator.GetRequest(property)), "LabelFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample( tagGenerator.DisplayFor(tagGenerator.GetRequest(property)), "DisplayFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample(tagGenerator.InputFor(tagGenerator.GetRequest(property)), "InputFor({0})".ToFormat(propertyExpression))); var propExample = new PropertyExample { Source = propertySource, Examples = propExamples }; examples.Add(propExample); }); model.Examples = examples; }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var examples = new List <PropertyExample>(); var tagGenerator = _generatorFactory.GeneratorFor(context.ModelType); tagGenerator.SetModel(context.Instance); _populator.PopulateInstance(context.Instance, context.SimpleProperties()); context .SimpleProperties() .Each(prop => { Accessor property; if (context.PropertyChain.Any()) { property = new PropertyChain(context .PropertyChain .Concat <PropertyInfo>(new[] { prop }) .Select(x => new PropertyValueGetter(x)) .ToArray()); } else { property = new SingleProperty(prop); } var propertyExpression = "x => x." + property.PropertyNames.Join("."); var propertySource = _sourceGenerator.SourceFor(prop); var propExamples = new List <Example>(); propExamples.Add(createExample(tagGenerator.LabelFor(tagGenerator.GetRequest(property)), "LabelFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample( tagGenerator.DisplayFor(tagGenerator.GetRequest(property)), "DisplayFor({0})".ToFormat(propertyExpression))); propExamples.Add(createExample(tagGenerator.InputFor(tagGenerator.GetRequest(property)), "InputFor({0})".ToFormat(propertyExpression))); var propExample = new PropertyExample { Source = propertySource, Examples = propExamples }; examples.Add(propExample); }); model.Examples = examples; }
public void Enrich(HtmlConventionsPreviewContext context, HtmlConventionsPreviewViewModel model) { var links = new List<PropertyLink>(); context .NonConvertibleProperties() .Each(prop => { var path = "{0}-{1}".ToFormat(context.Path, prop.Name); var type = prop.PropertyType; if (type.IsInterface || type.IsAbstract || type.IsGenericType || type.GetConstructor(new Type[0]) == null) { path = ""; } links.Add(new PropertyLink { Path = path, Source = _sourceGenerator.SourceFor(prop) }); }); model.Links = links; }
public void setup() { _builder = new PropertyLinksBuilder(new PropertySourceGenerator()); _model = new HtmlConventionsPreviewViewModel(); _context = ObjectMother.BasicPreviewContext(); }
public void setup() { _context = ObjectMother.BasicPreviewContext(); }