public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();
            IEdmModel model = new EdmModel();
            string routeName = "name";
            string routePrefix = "prefix";
            var pathHandler = new DefaultODataPathHandler();
            var conventions = new List<IODataRoutingConvention>();

            // Act
            routes.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, conventions);

            // Assert
            IHttpRoute odataRoute = routes[routeName];
            Assert.Single(routes);
            Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate);
            Assert.Equal(2, odataRoute.Constraints.Count);

            var odataPathConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataPathRouteConstraint>());
            Assert.Same(model, odataPathConstraint.EdmModel);
            Assert.IsType<DefaultODataPathHandler>(odataPathConstraint.PathHandler);
            Assert.NotNull(odataPathConstraint.RoutingConventions);

            var odataVersionConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataVersionConstraint>());
            Assert.Equal(ODataVersion.V1, odataVersionConstraint.MinVersion);
            Assert.Equal(ODataVersion.V3, odataVersionConstraint.MaxVersion);
        }
 public void Can_find_action(string actionName, string url)
 {
     IEdmModel model = GetModel();
     ODataPath path = new DefaultODataPathHandler().Parse(model, url);
     Assert.NotNull(path); // Guard
     ODataDeserializerContext context = new ODataDeserializerContext { Path = path, Model = model };
     IEdmFunctionImport action = ODataActionPayloadDeserializer.GetFunctionImport(context);
     Assert.NotNull(action);
     Assert.Equal(actionName, action.Name);
 }
        public void Can_find_action_overload_using_bindingparameter_type()
        {
            IEdmModel model = GetModel();
            string url = "Vehicles(8)/System.Web.Http.OData.Builder.TestModels.Car/Wash";
            ODataPath path = new DefaultODataPathHandler().Parse(model, url);
            Assert.NotNull(path); // Guard
            ODataDeserializerContext context = new ODataDeserializerContext { Path = path, Model = model };

            IEdmFunctionImport action = ODataActionPayloadDeserializer.GetFunctionImport(context);

            Assert.NotNull(action);
            Assert.Equal("Wash", action.Name);

        }
        public void AdvancedMapODataRoute_ConfiguresARoute_WithAnODataRouteConstraint()
        {
            HttpRouteCollection routes = new HttpRouteCollection();
            IEdmModel model = new EdmModel();
            string routeName = "name";
            string routePrefix = "prefix";
            var pathHandler = new DefaultODataPathHandler();
            var conventions = new List<IODataRoutingConvention>();

            routes.MapODataRoute(routeName, routePrefix, model, pathHandler, conventions);

            IHttpRoute odataRoute = routes[routeName];
            Assert.Single(routes);
            Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate);
            var constraint = Assert.Single(odataRoute.Constraints);
            var odataConstraint = Assert.IsType<ODataPathRouteConstraint>(constraint.Value);
            Assert.Same(model, odataConstraint.EdmModel);
            Assert.Same(pathHandler, odataConstraint.PathHandler);
            Assert.Same(conventions, odataConstraint.RoutingConventions);
        }
        public void GetSingleEntityEntityType_ReturnsEntityTypeForSingleEntityResources(string odataPath, string typeName)
        {
            // Arrange
            IEdmModel model = SetupModel();
            IODataPathHandler pathHandler = new DefaultODataPathHandler();
            ODataPath path = pathHandler.Parse(model, odataPath);

            // Guard
            Assert.NotNull(path);

            // Act
            IEdmEntityType entityType = ETagMessageHandler.GetSingleEntityEntityType(path);

            // Assert
            Assert.NotNull(entityType);
            Assert.Equal(typeName, entityType.FullName());
        }
        /// <summary>
        /// Gets the <see cref="IODataPathHandler"/> to use for generating links.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="IODataPathHandler"/> to use for generating links.</returns>
        public static IODataPathHandler GetODataPathHandler(this HttpRequestMessage request)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            object pathHandler;
            if (!request.Properties.TryGetValue(ODataPathHandlerKey, out pathHandler))
            {
                IODataPathHandler defaultPathHandler = new DefaultODataPathHandler();
                request.SetODataPathHandler(defaultPathHandler);
                return defaultPathHandler;
            }
            return pathHandler as IODataPathHandler;
        }
        /// <summary>
        /// Gets the <see cref="IODataPathHandler"/> from the configuration.
        /// </summary>
        /// <param name="configuration">The server's configuration.</param>
        /// <returns>The <see cref="IODataPathHandler"/> for the configuration.</returns>
        public static IODataPathHandler GetODataPathHandler(this HttpConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            object pathHandler;
            if (!configuration.Properties.TryGetValue(ODataPathHandlerKey, out pathHandler))
            {
                IEdmModel model = configuration.GetEdmModel();
                if (model == null)
                {
                    return null;
                }
                else
                {
                    IODataPathHandler defaultPathHandler = new DefaultODataPathHandler(model);
                    configuration.SetODataPathHandler(defaultPathHandler);
                    return defaultPathHandler;
                }
            }
            return pathHandler as IODataPathHandler;
        }