예제 #1
0
            public static HtmlHelper Get(
                Action <IRouteBuilder> mapRoute,
                string host,
                string appRoot,
                string controller,
                string action,
                string area,
                string expectedUrl)
            {
                var services       = ConfigurationFactories.ServiceProviderFacotry.Get();
                var routeBuilder   = ConfigurationFactories.RouteBuilderFactory.Get(services);
                var httpContext    = ConfigurationFactories.HttpContextFactory.Get(services, host, appRoot);
                var mvcViewOptions = ConfigurationFactories.OptionsFactory.GetMvcViewOptions();

                mapRoute(routeBuilder);

                var actionContext = ConfigurationFactories.ActionContextFactory.Get(httpContext, new ActionDescriptor());

                ActionContextVisitor.Visit(actionContext, routeBuilder, action, controller, area);

                var metadataProvider = new EmptyModelMetadataProvider();
                var htmlGenerator    = new TestHtmlGenerator(metadataProvider, mvcViewOptions, new SubdomainUrlHelperFactory());
                var htmlHelper       = new HtmlHelper(htmlGenerator, Mock.Of <ICompositeViewEngine>(), metadataProvider, Mock.Of <IViewBufferScope>(), new HtmlTestEncoder(), UrlTestEncoder.Default);

                //must call Contextualize before using htmlHelper instance
                htmlHelper.Contextualize(ConfigurationFactories.ViewContextFactory.Get(actionContext, null, metadataProvider, new ModelStateDictionary()));
                return(htmlHelper);
            }
예제 #2
0
            public static TagHelper GetForm(
                Action <IRouteBuilder> mapRoute,
                string host,
                string appRoot,
                string controller,
                string action,
                string area,
                string expectedUrl)
            {
                var services       = ConfigurationFactories.ServiceProviderFacotry.Get();
                var routeBuilder   = ConfigurationFactories.RouteBuilderFactory.Get(services);
                var httpContext    = ConfigurationFactories.HttpContextFactory.Get(services, host, appRoot);
                var mvcViewOptions = ConfigurationFactories.OptionsFactory.GetMvcViewOptions();

                mapRoute(routeBuilder);

                var actionContext = ConfigurationFactories.ActionContextFactory.Get(httpContext, new ActionDescriptor());

                ActionContextVisitor.Visit(actionContext, routeBuilder, action, controller, area);

                var metadataProvider = new EmptyModelMetadataProvider();
                var htmlGenerator    = new TestHtmlGenerator(metadataProvider, mvcViewOptions, new SubdomainUrlHelperFactory());
                var tagHelper        = new Microsoft.AspNetCore.Mvc.TagHelpers.FormTagHelper(htmlGenerator)
                {
                    ViewContext = ConfigurationFactories.ViewContextFactory.Get(actionContext, null, metadataProvider, new ModelStateDictionary()),
                    Action      = action,
                    Controller  = controller,
                    Antiforgery = false
                };

                if (area != null)
                {
                    tagHelper.Area = area;
                }

                return(tagHelper);
            }