private static void SetupRoutes(HttpContext httpContext, string requestMethod, string requestPath)
        {
            httpContext.Request.Method = requestMethod;

            var feature = new RouteValuesFeature
            {
                RouteValues =
                {
                    ["controller"] = "theController",
                    ["action"]     = "theAction"
                }
            };

            var pathSegments = requestPath.Split("/", StringSplitOptions.RemoveEmptyEntries);

            if (pathSegments.Length > 1)
            {
                feature.RouteValues["id"] = pathSegments[1];

                if (pathSegments.Length >= 3)
                {
                    feature.RouteValues["relationshipName"] = pathSegments.Last();
                }
            }

            if (pathSegments.Contains("relationships"))
            {
                feature.RouteValues["action"] = "Relationship";
            }

            httpContext.Features.Set <IRouteValuesFeature>(feature);
            httpContext.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(), null));
        }
Пример #2
0
        private static DefaultHttpContext CreateHttpContext(string path, bool isRelationship = false, string action = "", string id = null)
        {
            var context = new DefaultHttpContext();

            context.Request.Path  = new PathString(path);
            context.Response.Body = new MemoryStream();

            var feature = new RouteValuesFeature
            {
                RouteValues =
                {
                    ["controller"] = "fake!",
                    ["action"]     = isRelationship ? "GetRelationship" : action
                }
            };

            if (id != null)
            {
                feature.RouteValues["id"] = id;
            }

            context.Features.Set <IRouteValuesFeature>(feature);

            var controllerActionDescriptor = new ControllerActionDescriptor
            {
                ControllerTypeInfo = (TypeInfo)typeof(object)
            };

            context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(controllerActionDescriptor), null));
            return(context);
        }
 private static DefaultHttpContext CreateHttpContext(string path, bool isRelationship = false, string action = "", string id =null)
 {
     var context = new DefaultHttpContext();
     context.Request.Path = new PathString(path);
     context.Response.Body = new MemoryStream();
     var feature = new RouteValuesFeature();
     feature.RouteValues["controller"] = "fake!";
     feature.RouteValues["action"] = isRelationship ? "GetRelationship" : action;
     if(id != null)
     {
         feature.RouteValues["id"] = id;
     }
     context.Features.Set<IRouteValuesFeature>(feature);
     return context;
 }
        private void parseRoute(HttpContext context, string path)
        {
            var value = new RouteValueDictionary();

            try
            {
                matcher.TryMatch(path, value);
            }
            catch
            {
            }
            var feature = new RouteValuesFeature
            {
                RouteValues = value
            };

            context.Features.Set <IRouteValuesFeature>(feature);
        }