public void GenerateNavigationLink_GeneratesCorrectLink_EvenIfRouteDataPointsToADifferentController()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var orders = builder.AddEntitySet("Orders", builder.AddEntity(typeof(NavigationLinksGenerationConventionTest_Order)));

            IEdmModel model        = builder.GetEdmModel();
            var       edmEntitySet = model.EntityContainers().Single().EntitySets().Single();

            HttpConfiguration configuration = new HttpConfiguration();
            string            routeName     = "Route";

            configuration.Routes.MapODataRoute(routeName, null, model);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

            request.SetConfiguration(configuration);
            request.SetODataRouteName(routeName);

            Uri uri =
                NavigationLinksGenerationConvention.GenerateNavigationPropertyLink(
                    new EntityInstanceContext
            {
                EdmModel       = model,
                EntityInstance = new NavigationLinksGenerationConventionTest_Order {
                    ID = 100
                },
                EntitySet  = edmEntitySet,
                EntityType = edmEntitySet.ElementType,
                Url        = request.GetUrlHelper()
            },
                    edmEntitySet.ElementType.NavigationProperties().Single(),
                    orders,
                    includeCast: false);

            Assert.Equal("http://localhost/Orders(100)/Customer", uri.AbsoluteUri);
        }
        public void GenerateNavigationLink_GeneratesCorrectLink_EvenIfRouteDataPointsToADifferentController()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var orders = builder.AddEntitySet("Orders", builder.AddEntity(typeof(NavigationLinksGenerationConventionTest_Order)));

            IEdmModel model        = builder.GetEdmModel();
            var       edmEntitySet = model.EntityContainers().Single().EntitySets().Single();

            HttpConfiguration configuration = new HttpConfiguration();
            var route = configuration.Routes.MapHttpRoute(ODataRouteNames.PropertyNavigation, "{controller}({parentId})/{navigationProperty}");
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey]     = new HttpRouteData(route, new HttpRouteValueDictionary(new { controller = "Customers" }));

            Uri uri =
                NavigationLinksGenerationConvention.GenerateNavigationPropertyLink(
                    new EntityInstanceContext
            {
                EdmModel       = model,
                EntityInstance = new NavigationLinksGenerationConventionTest_Order {
                    ID = 100
                },
                EntitySet  = edmEntitySet,
                EntityType = edmEntitySet.ElementType,
                UrlHelper  = request.GetUrlHelper()
            },
                    edmEntitySet.ElementType.NavigationProperties().Single(),
                    orders,
                    includeCast: false);

            Assert.Equal("http://localhost/Orders(100)/Customer", uri.AbsoluteUri);
        }
        public void GenerateNavigationLink_GeneratesLink()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var orders = builder.AddEntitySet("Orders", builder.AddEntity(typeof(NavigationLinksGenerationConventionTest_Order)));

            IEdmModel model        = builder.GetEdmModel();
            var       edmEntitySet = model.EntityContainers().Single().EntitySets().Single();

            HttpConfiguration configuration = new HttpConfiguration();

            configuration.EnableOData(model);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");

            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey]     = new HttpRouteData(new HttpRoute());

            Uri uri =
                NavigationLinksGenerationConvention.GenerateNavigationPropertyLink(
                    new EntityInstanceContext
            {
                EdmModel       = model,
                EntityInstance = new NavigationLinksGenerationConventionTest_Order {
                    ID = 100
                },
                EntitySet   = edmEntitySet,
                EntityType  = edmEntitySet.ElementType,
                UrlHelper   = request.GetUrlHelper(),
                PathHandler = new DefaultODataPathHandler(model)
            },
                    edmEntitySet.ElementType.NavigationProperties().Single(),
                    orders,
                    includeCast: false);

            Assert.Equal("http://localhost/Orders(100)/Customer", uri.AbsoluteUri);
        }
 public void DefaultCtor_DoesntThrow()
 {
     NavigationLinksGenerationConvention convention = new NavigationLinksGenerationConvention();
 }
 public void DefaultCtor_DoesntThrow()
 {
     NavigationLinksGenerationConvention convention = new NavigationLinksGenerationConvention();
 }