RegisterRoutes() public static method

public static RegisterRoutes ( RouteCollection routes ) : void
routes RouteCollection
return void
示例#1
0
        public static void SetupUrlHelper(Controller controller, Mock <HttpContextBase> mockHttpContext)
        {
            var routes = new RouteCollection();

            Routes.RegisterRoutes(routes);
            controller.Url = new UrlHelper(new RequestContext(mockHttpContext.Object, new RouteData()), routes);
        }
示例#2
0
        public static UrlHelper MockUrlHelper()
        {
            // We default all requests to HTTPS in our tests.
            var mockHttpContext  = new Mock <HttpContextBase>(MockBehavior.Loose);
            var mockHttpRequest  = new Mock <HttpRequestBase>(MockBehavior.Strict);
            var mockHttpResponse = new Mock <HttpResponseBase>(MockBehavior.Strict);

            mockHttpContext.Setup(httpContext => httpContext.Request).Returns(mockHttpRequest.Object);
            mockHttpContext.Setup(httpContext => httpContext.Response).Returns(mockHttpResponse.Object);
            mockHttpRequest.Setup(httpRequest => httpRequest.Url).Returns(new Uri(GallerySiteRootHttps));
            mockHttpRequest.Setup(httpRequest => httpRequest.ApplicationPath).Returns(GallerySiteRootHttps);
            mockHttpRequest.Setup(httpRequest => httpRequest.ServerVariables).Returns(new NameValueCollection());
            mockHttpRequest.Setup(httpRequest => httpRequest.IsSecureConnection).Returns(false);

            string          value     = null;
            Action <string> saveValue = x =>
            {
                value = x;
            };
            Func <String> restoreValue = () => value;

            mockHttpResponse.Setup(httpResponse => httpResponse.ApplyAppPathModifier(It.IsAny <string>()))
            .Callback(saveValue).Returns(restoreValue);
            var requestContext = new RequestContext(mockHttpContext.Object, new RouteData());
            var routes         = new RouteCollection();

            Routes.RegisterRoutes(routes);

            return(new UrlHelper(requestContext, routes));
        }
示例#3
0
        public static UrlHelper MockUrlHelper()
        {
            var mockHttpContext  = new Mock <HttpContextBase>(MockBehavior.Loose);
            var mockHttpRequest  = new Mock <HttpRequestBase>(MockBehavior.Strict);
            var mockHttpResponse = new Mock <HttpResponseBase>(MockBehavior.Strict);

            mockHttpContext.Setup(httpContext => httpContext.Request).Returns(mockHttpRequest.Object);
            mockHttpContext.Setup(httpContext => httpContext.Response).Returns(mockHttpResponse.Object);
            mockHttpRequest.Setup(httpRequest => httpRequest.Url).Returns(new Uri("http://unittest.nuget.org/"));
            mockHttpRequest.Setup(httpRequest => httpRequest.ApplicationPath).Returns("http://unittest.nuget.org/");
            mockHttpRequest.Setup(httpRequest => httpRequest.ServerVariables).Returns(new NameValueCollection());

            string          value     = null;
            Action <string> saveValue = x =>
            {
                value = x;
            };
            Func <String> restoreValue = () => value;

            mockHttpResponse.Setup(httpResponse => httpResponse.ApplyAppPathModifier(It.IsAny <string>()))
            .Callback(saveValue).Returns(restoreValue);
            var requestContext = new RequestContext(mockHttpContext.Object, new RouteData());
            var routes         = new RouteCollection();

            Routes.RegisterRoutes(routes);
            return(new UrlHelper(requestContext, routes));
        }
示例#4
0
        private static void AppPostStart()
        {
            Routes.RegisterRoutes(RouteTable.Routes);
            SetCustomRouteHandler();

            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#5
0
        private static void AppPostStart()
        {
            Routes.RegisterRoutes(RouteTable.Routes);
            // deprecated - the aspnet:UseHostHeaderForRequestUrl setting in the web.config file
            //  should now process the urls accurately
            //SetCustomRouteHandler();

            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#6
0
        private static void AppPostStart()
        {
            Routes.RegisterRoutes(RouteTable.Routes);
            Routes.RegisterServiceRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();

            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());
            GlobalFilters.Filters.Add(new ReadOnlyModeErrorFilter());
            GlobalFilters.Filters.Add(new AntiForgeryErrorFilter());
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#7
0
        private static void AppPostStart()
        {
            RegisterGlobalFilters(GlobalFilters.Filters);

            Routes.RegisterRoutes(RouteTable.Routes);

#if !DEBUG
            Database.SetInitializer <EntitiesContext>(null);
#endif

            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#8
0
        public static void Start()
        {
            UpdateDatabase();
            Routes.RegisterRoutes(RouteTable.Routes);

            DynamicDataEFCodeFirst.Registration.Register(RouteTable.Routes);

            // TODO: move profile bootstrapping and container bootstrapping to here
            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());

            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#9
0
        private static void AppPostStart(IAppConfiguration configuration)
        {
            Routes.RegisterRoutes(RouteTable.Routes, configuration.FeedOnlyMode);
            Routes.RegisterServiceRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();

            GlobalFilters.Filters.Add(new SendErrorsToTelemetryAttribute {
                View = "~/Views/Errors/InternalError.cshtml"
            });
            GlobalFilters.Filters.Add(new ReadOnlyModeErrorFilter());
            GlobalFilters.Filters.Add(new AntiForgeryErrorFilter());
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#10
0
        private static void AppPostStart()
        {
            RegisterGlobalFilters(GlobalFilters.Filters);

            Routes.RegisterRoutes(RouteTable.Routes);

#if !DEBUG
            Database.SetInitializer <EntitiesContext>(null);
#else
            var ensureImportsForRelease = Database.DefaultConnectionFactory;
#endif

            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#11
0
        private static void AppPostStart()
        {
            Routes.RegisterRoutes(RouteTable.Routes);
            Routes.RegisterServiceRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();

            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());
            GlobalFilters.Filters.Add(new ReadOnlyModeErrorFilter());
            GlobalFilters.Filters.Add(new RequireRemoteHttpsAttribute()
            {
                OnlyWhenAuthenticated = true
            });
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#12
0
        // We only need this method because testing URL generation is a pain.
        // Alternatively, we could write our own service for generating URLs.
        public static Mock <HttpContextBase> SetupHttpContextMockForUrlGeneration(Mock <HttpContextBase> httpContext, Controller controller)
        {
            // We default all requests to HTTPS in our tests.
            httpContext.Setup(c => c.Request.Url).Returns(new Uri(GallerySiteRootHttps));
            httpContext.Setup(c => c.Request.ApplicationPath).Returns("/");
            httpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);
            var requestContext    = new RequestContext(httpContext.Object, new RouteData());
            var controllerContext = new ControllerContext(requestContext, controller);

            controller.ControllerContext = controllerContext;
            var routeCollection = new RouteCollection();

            Routes.RegisterRoutes(routeCollection);
            controller.Url = new UrlHelper(requestContext, routeCollection);
            return(httpContext);
        }
示例#13
0
        private static void AppPostStart(IAppConfiguration configuration)
        {
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            NuGetODataConfig.Register(GlobalConfiguration.Configuration);

            // Attach correlator
            GlobalConfiguration.Configuration.MessageHandlers.Add(new WebApiCorrelationHandler());

            Routes.RegisterRoutes(RouteTable.Routes, configuration.FeedOnlyMode);
            AreaRegistration.RegisterAllAreas();

            GlobalFilters.Filters.Add(new SendErrorsToTelemetryAttribute {
                View = "~/Views/Errors/InternalError.cshtml"
            });
            GlobalFilters.Filters.Add(new ReadOnlyModeErrorFilter());
            GlobalFilters.Filters.Add(new AntiForgeryErrorFilter());
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#14
0
        private static void AppPostStart()
        {
            ModelBinders.Binders.Add(typeof(PackageScanResult), new BaseModelBinder <PackageScanResult>());

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new CSharpRazorViewEngine());

            RegisterGlobalFilters(GlobalFilters.Filters);

            Routes.RegisterRoutes(RouteTable.Routes);

#if !DEBUG
            Database.SetInitializer <EntitiesContext>(null);
#else
            var ensureImportsForRelease = Database.DefaultConnectionFactory;
#endif

            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }
示例#15
0
        public static void SetupUrlHelperForUrlGeneration(Controller controller, Uri address)
        {
            var mockHttpContext = new Mock <HttpContextBase>();

            mockHttpContext.Setup(c => c.Request.Url).Returns(address);
            mockHttpContext.Setup(c => c.Request.ApplicationPath).Returns("/");
            mockHttpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);

            var requestContext = new RequestContext(mockHttpContext.Object, new RouteData());

            var controllerContext = new ControllerContext(requestContext, controller);

            controller.ControllerContext = controllerContext;

            var routes = new RouteCollection();

            Routes.RegisterRoutes(routes);
            controller.Url = new UrlHelper(requestContext, routes);
        }
示例#16
0
        public static void SetupUrlHelperForUrlGeneration(Controller controller)
        {
            // We default all requests to HTTPS in our tests.
            var mockHttpContext = new Mock <HttpContextBase>();

            mockHttpContext.Setup(c => c.Request.Url).Returns(new Uri(GallerySiteRootHttps));
            mockHttpContext.Setup(c => c.Request.ApplicationPath).Returns("/");
            mockHttpContext.Setup(c => c.Request.IsSecureConnection).Returns(true);
            mockHttpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);

            var requestContext = new RequestContext(mockHttpContext.Object, new RouteData());

            var controllerContext = new ControllerContext(requestContext, controller);

            controller.ControllerContext = controllerContext;

            var routes = new RouteCollection();

            Routes.RegisterRoutes(routes);
            controller.Url = new UrlHelper(requestContext, routes);
        }
示例#17
0
        private static void AppPostStart(IAppConfiguration configuration)
        {
            Routes.RegisterRoutes(RouteTable.Routes);
            Routes.RegisterServiceRoutes(RouteTable.Routes);
            AreaRegistration.RegisterAllAreas();


            GlobalFilters.Filters.Add(new ElmahHandleErrorAttribute());
            GlobalFilters.Filters.Add(new ReadOnlyModeErrorFilter());
            GlobalFilters.Filters.Add(new AntiForgeryErrorFilter());
            var googleAnalyticsId = configuration.GoogleAnalyticsPropertyId;

            if (googleAnalyticsId != null)
            {
                var tracker = new Tracker(googleAnalyticsId, configuration.SiteRoot, new CookieBasedAnalyticsSession());
                GlobalFilters.Filters.Add(new GoogleAnalyticsTracker.Web.Mvc.ActionTrackingAttribute(tracker, descriptor =>
                {
                    var controllerType = descriptor.ControllerDescriptor.ControllerType;
                    return(typeof(ApiController).IsAssignableFrom(controllerType) || typeof(JsonController).IsAssignableFrom(controllerType));
                }));
            }
            ValueProviderFactories.Factories.Add(new HttpHeaderValueProviderFactory());
        }