コード例 #1
0
        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"));
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        public HtmlConventionsPreviewViewModel Execute(HtmlConventionsPreviewRequestModel request)
        {
            var context = _contextFactory.BuildFromPath(request.OutputModel);
            var model = new HtmlConventionsPreviewViewModel();

            _decorators
                .Each(d => d.Enrich(context, model));

            return model;
        }
コード例 #4
0
        public HtmlConventionsPreviewViewModel Execute(HtmlConventionsPreviewRequestModel request)
        {
            var context = _contextFactory.BuildFromPath(request.OutputModel);
            var model   = new HtmlConventionsPreviewViewModel();

            _decorators
            .Each(d => d.Enrich(context, model));

            return(model);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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;
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 public void setup()
 {
     _builder = new DisplayPathBuilder();
     _model   = new HtmlConventionsPreviewViewModel();
 }
コード例 #11
0
 public void setup()
 {
     _builder = new PropertyLinksBuilder(new PropertySourceGenerator());
     _model   = new HtmlConventionsPreviewViewModel();
     _context = ObjectMother.BasicPreviewContext();
 }