public static IEdmNavigationProperty GetNavigationProperty(this ODataPath path)
        {
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            Contract.Assert(path.Segments != null);
            NavigationPathSegment navigationSegment = (NavigationPathSegment)path.Segments.FirstOrDefault(
                s => s is NavigationPathSegment);

            if (navigationSegment == null)
            {
                return(null);
            }

            return(navigationSegment.NavigationProperty);
        }
Exemple #2
0
        public void CanParseNavigateToSingleSegment()
        {
            // Arrange
            string                 odataPath          = "RoutingCustomers(100)/System.Web.Http.OData.Routing.VIP/RelationshipManager";
            string                 expectedText       = "RelationshipManager";
            IEdmEntitySet          expectedSet        = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "SalesPeople");
            IEdmNavigationProperty expectedEdmElement = _model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "VIP").NavigationProperties().SingleOrDefault(n => n.Name == "RelationshipManager");

            // Act
            ODataPath        path    = _parser.Parse(_model, odataPath);
            ODataPathSegment segment = path.Segments.Last();

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Same(expectedSet, path.EntitySet);
            Assert.Equal(expectedSet.ElementType, path.EdmType);
            NavigationPathSegment navigation = Assert.IsType <NavigationPathSegment>(segment);

            Assert.Same(expectedEdmElement, navigation.NavigationProperty);
        }
Exemple #3
0
        public void CanParseNavigateToCollectionSegment()
        {
            // Arrange
            string                 odataPath          = "RoutingCustomers(100)/Products";
            string                 expectedText       = "Products";
            IEdmEntitySet          expectedSet        = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "Products");
            IEdmNavigationProperty expectedEdmElement = _model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "RoutingCustomer").NavigationProperties().SingleOrDefault(n => n.Name == "Products");

            // Act
            ODataPath        path    = _parser.Parse(_model, odataPath);
            ODataPathSegment segment = path.Segments.Last();

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Same(expectedSet, path.EntitySet);
            Assert.Equal(expectedSet.ElementType, (path.EdmType as IEdmCollectionType).ElementType.Definition);
            NavigationPathSegment navigation = Assert.IsType <NavigationPathSegment>(segment);

            Assert.Same(expectedEdmElement, navigation.NavigationProperty);
        }
        public void CanParseNavigateToSingleSegment()
        {
            // Arrange
            string                 testUrl            = "http://myservice/Customers(100)/System.Web.Http.OData.Routing.VIP/RelationshipManager";
            string                 expectedText       = "RelationshipManager";
            IEdmEntitySet          expectedSet        = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "SalesPeople");
            IEdmNavigationProperty expectedEdmElement = _parser.Model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "VIP").NavigationProperties().SingleOrDefault(n => n.Name == "RelationshipManager");
            Uri uri     = new Uri(testUrl);
            Uri baseUri = new Uri("http://myservice/");

            // Act
            ODataPath        path    = _parser.Parse(uri, baseUri);
            ODataPathSegment segment = path.Segments.Last.Value;

            // Assert
            Assert.NotNull(segment);
            Assert.NotNull(segment.Previous);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Same(expectedSet, segment.EntitySet);
            Assert.Equal(expectedSet.ElementType, segment.EdmType);
            NavigationPathSegment navigation = Assert.IsType <NavigationPathSegment>(segment);

            Assert.Same(expectedEdmElement, navigation.NavigationProperty);
        }
        public void CanParseNavigateToCollectionSegment()
        {
            // Arrange
            string                 testUrl            = "http://myservice/Customers(100)/Products";
            string                 expectedText       = "Products";
            IEdmEntitySet          expectedSet        = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "Products");
            IEdmNavigationProperty expectedEdmElement = _parser.Model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "Customer").NavigationProperties().SingleOrDefault(n => n.Name == "Products");
            Uri uri     = new Uri(testUrl);
            Uri baseUri = new Uri("http://myservice/");

            // Act
            ODataPath        path    = _parser.Parse(uri, baseUri);
            ODataPathSegment segment = path.Segments.Last.Value;

            // Assert
            Assert.NotNull(segment);
            Assert.NotNull(segment.Previous);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Same(expectedSet, segment.EntitySet);
            Assert.Equal(expectedSet.ElementType, (segment.EdmType as IEdmCollectionType).ElementType.Definition);
            NavigationPathSegment navigation = Assert.IsType <NavigationPathSegment>(segment);

            Assert.Same(expectedEdmElement, navigation.NavigationProperty);
        }