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 should_populate_instance() { MockFor <IModelPopulator>() .Expect(p => p.PopulateInstance(_context.Instance, _context.SimpleProperties())) .IgnoreArguments(); ClassUnderTest .Enrich(_context, _model); VerifyCallsFor <IModelPopulator>(); }
public void should_select_ancillary_properties() { _context .SimpleProperties() .ShouldHaveCount(1); }