Ejemplo n.º 1
0
        public void GenerateLinkDirectly_ReturnsNull_IfHelperRequestHasNoConfiguration()
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            ODataRoute odataRoute = new ODataRoute("prefix", pathConstraint: null);

            Assert.Null(odataRoute.GenerateLinkDirectly(request, "odataPath"));
        }
Ejemplo n.º 2
0
        public void GenerateLinkDirectly_ReturnsNull_IfHelperRequestHasNoConfiguration()
        {
            HttpRequestMessage request    = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            ODataRoute         odataRoute = new ODataRoute("prefix", pathConstraint: null);

            Assert.Null(odataRoute.GenerateLinkDirectly(request, "odataPath"));
        }
Ejemplo n.º 3
0
        public void GenerateLinkDirectly_ReturnsNull_IfRouteTemplateHasParameterInPrefix()
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            HttpConfiguration config = new HttpConfiguration(new HttpRouteCollection("http://localhost/vpath"));
            request.SetConfiguration(config);
            ODataRoute odataRoute = new ODataRoute("{prefix}", pathConstraint: null);

            Assert.Null(odataRoute.GenerateLinkDirectly(request, "odataPath"));
        }
Ejemplo n.º 4
0
        public void GenerateLinkDirectly_ReturnsNull_IfRouteTemplateHasParameterInPrefix()
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            HttpConfiguration  config  = new HttpConfiguration(new HttpRouteCollection("http://localhost/vpath"));

            request.SetConfiguration(config);
            ODataRoute odataRoute = new ODataRoute("{prefix}", pathConstraint: null);

            Assert.Null(odataRoute.GenerateLinkDirectly(request, "odataPath"));
        }
Ejemplo n.º 5
0
        public void GetVirtualPath_MatchesHttpRoute(string odataPath)
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            HttpConfiguration config = new HttpConfiguration(new HttpRouteCollection("http://localhost/vpath"));
            request.SetConfiguration(config);

            IHttpRoute httpRoute = config.Routes.CreateRoute("prefix/{*odataPath}", defaults: null, constraints: null);
            ODataRoute odataRoute = new ODataRoute("prefix", pathConstraint: null);

            // Test that the link generated by ODataRoute matches the one generated by HttpRoute
            Assert.Equal(
                httpRoute.GetVirtualPath(request, new HttpRouteValueDictionary { { "odataPath", odataPath }, { "httproute", true } }).VirtualPath,
                odataRoute.GetVirtualPath(request, new HttpRouteValueDictionary { { "odataPath", odataPath }, { "httproute", true } }).VirtualPath);
        }
Ejemplo n.º 6
0
        public void GetVirtualPath_MatchesHttpRoute(string odataPath)
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
            HttpConfiguration  config  = new HttpConfiguration(new HttpRouteCollection("http://localhost/vpath"));

            request.SetConfiguration(config);

            IHttpRoute httpRoute  = config.Routes.CreateRoute("prefix/{*odataPath}", defaults: null, constraints: null);
            ODataRoute odataRoute = new ODataRoute("prefix", pathConstraint: null);

            // Test that the link generated by ODataRoute matches the one generated by HttpRoute
            Assert.Equal(
                httpRoute.GetVirtualPath(request, new HttpRouteValueDictionary {
                { "odataPath", odataPath }, { "httproute", true }
            }).VirtualPath,
                odataRoute.GetVirtualPath(request, new HttpRouteValueDictionary {
                { "odataPath", odataPath }, { "httproute", true }
            }).VirtualPath);
        }
Ejemplo n.º 7
0
 public void HasRelaxedODataVersionConstraint_SetValue()
 {
     ODataRoute odataRoute = new ODataRoute(routePrefix: null, pathConstraint: null).HasRelaxedODataVersionConstraint();
     Assert.True(((ODataVersionConstraint)odataRoute.Constraints[ODataRouteConstants.VersionConstraintName]).IsRelaxedMatch);
 }
Ejemplo n.º 8
0
        public void SetODataVersionConstraint_SetValue()
        {
            ODataRoute odataRoute = new ODataRoute(routePrefix: null, pathConstraint: null);

            Assert.Equal(true, ((ODataVersionConstraint)odataRoute.Constraints[ODataRouteConstants.VersionConstraintName]).IsRelaxedMatch);
        }
Ejemplo n.º 9
0
        public void ODataVersionConstraint_DefaultIsRelaxedValueIsTrue()
        {
            ODataRoute odataRoute = new ODataRoute(routePrefix: null, pathConstraint: null);

            Assert.True(((ODataVersionConstraint)odataRoute.Constraints[ODataRouteConstants.VersionConstraintName]).IsRelaxedMatch);
        }
Ejemplo n.º 10
0
 public void SetODataVersionConstraint_SetValue()
 {
     ODataRoute odataRoute = new ODataRoute(routePrefix: null, pathConstraint: null);
     Assert.Equal(true, ((ODataVersionConstraint)odataRoute.Constraints[ODataRouteConstants.VersionConstraintName]).IsRelaxedMatch);
 }
        public static ODataRoute MapODataRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model,
            IODataPathHandler pathHandler, IEnumerable<IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            if (!String.IsNullOrEmpty(routePrefix))
            {
                int prefixLastIndex = routePrefix.Length - 1;
                if (routePrefix[prefixLastIndex] == '/')
                {
                    // Remove the last trailing slash if it has one.
                    routePrefix = routePrefix.Substring(0, routePrefix.Length - 1);
                }
            }

            if (batchHandler != null)
            {
                batchHandler.ODataRouteName = routeName;
                string batchTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch;
                routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler);
            }

            ODataPathRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions);
            ODataRoute odataRoute = new ODataRoute(routePrefix, routeConstraint);
            routes.Add(routeName, odataRoute);

            return odataRoute;
        }