public void CanParseActionBoundToCollectionSegment()
        {
            // Arrange
            string             testUrl            = "http://myservice/Customers/System.Web.Http.OData.Routing.VIP/GetMostProfitable";
            string             expectedText       = "Default.Container.GetMostProfitable";
            IEdmFunctionImport expectedEdmElement = _parser.Model.EntityContainers().First().FunctionImports().SingleOrDefault(p => p.Name == "GetMostProfitable");
            IEdmEntitySet      expectedSet        = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(e => e.Name == "Customers");
            IEdmType           expectedType       = expectedEdmElement.ReturnType.Definition;
            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.Same(expectedType, segment.EdmType);
            ActionPathSegment action = Assert.IsType <ActionPathSegment>(segment);

            Assert.Same(expectedEdmElement, action.Action);
        }
Пример #2
0
        public void Parse_WorksOnEncodedCharacters()
        {
            string odataPath = "üCategories";

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

            Assert.NotNull(path);
            Assert.Equal("~/entityset", path.PathTemplate);
            Assert.Equal("üCategories", segment.ToString());
        }
Пример #3
0
        public void CanParseMetadataUrl()
        {
            string odataPath = "$metadata";

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

            // Assert
            Assert.NotNull(path);
            Assert.Null(path.EntitySet);
            Assert.Null(path.EdmType);
            Assert.Equal("$metadata", segment.ToString());
        }
Пример #4
0
        public void CanParseBatchUrl()
        {
            // Arrange
            string odataPath = "$batch";

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

            // Assert
            Assert.NotNull(path);
            Assert.NotNull(segment);
            Assert.Null(path.EntitySet);
            Assert.Null(path.EdmType);
            Assert.Equal("$batch", segment.ToString());
        }
Пример #5
0
        public void CanParsePropertyValueSegment()
        {
            // Arrange
            string odataPath = "RoutingCustomers(1)/Name/$value";

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

            // Assert
            Assert.NotNull(segment);
            Assert.Equal("$value", segment.ToString());
            Assert.Null(path.EntitySet);
            Assert.NotNull(path.EdmType);
            Assert.Equal("Edm.String", (path.EdmType as IEdmPrimitiveType).FullName());
        }
        public void CanParseMetadataUrl()
        {
            string testUrl = "http://myservice/$metadata";
            Uri    uri     = new Uri(testUrl);
            Uri    baseUri = new Uri("http://myservice/");

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

            // Assert
            Assert.NotNull(path);
            Assert.Null(path.EntitySet);
            Assert.Null(path.EdmType);
            Assert.Equal("$metadata", segment.ToString());
            Assert.NotNull(segment.Previous);
            Assert.Equal("http://myservice/", segment.Previous.ToString());
        }
        public void CanParsePropertyValueSegment()
        {
            // Arrange
            string testUrl = "http://myservice/Customers(1)/Name/$value";
            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.Equal("$value", segment.ToString());
            Assert.Null(segment.EntitySet);
            Assert.NotNull(segment.EdmType);
            Assert.Equal("Edm.String", (segment.EdmType as IEdmPrimitiveType).FullName());
        }
Пример #8
0
        public void CanParseKeyUrl()
        {
            // Arrange
            string        odataPath    = "RoutingCustomers(112)";
            string        expectedText = "112";
            IEdmEntitySet expectedSet  = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "RoutingCustomers");

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

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.IsType <KeyValuePathSegment>(segment);
            Assert.Same(expectedSet, path.EntitySet);
            Assert.Same(expectedSet.ElementType, path.EdmType);
        }
Пример #9
0
        public void CanParseCastEntitySegment()
        {
            // Arrange
            string         odataPath    = "RoutingCustomers(100)/System.Web.Http.OData.Routing.VIP";
            string         expectedText = "System.Web.Http.OData.Routing.VIP";
            IEdmEntitySet  expectedSet  = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "RoutingCustomers");
            IEdmEntityType expectedType = _model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "VIP");

            // 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(expectedType, path.EdmType);
        }
Пример #10
0
        public void CanParseEntitySetUrl()
        {
            // Arrange
            string        odataPath    = "RoutingCustomers";
            string        expectedText = "RoutingCustomers";
            IEdmEntitySet expectedSet  = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "RoutingCustomers");

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

            // Assert
            Assert.NotNull(path);
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Same(expectedSet, path.EntitySet);
            Assert.Same(expectedSet.ElementType, (path.EdmType as IEdmCollectionType).ElementType.Definition);
        }
Пример #11
0
        public void CanParsePropertySegment()
        {
            // Arrange
            string       odataPath          = "RoutingCustomers(112)/Name";
            string       expectedText       = "Name";
            IEdmProperty expectedEdmElement = _model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(e => e.Name == "RoutingCustomer").Properties().SingleOrDefault(p => p.Name == "Name");
            IEdmType     expectedType       = expectedEdmElement.Type.Definition;

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

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Null(path.EntitySet);
            PropertyAccessPathSegment propertyAccess = Assert.IsType <PropertyAccessPathSegment>(segment);

            Assert.Same(expectedEdmElement, propertyAccess.Property);
        }
Пример #12
0
        public void CanParseRootProcedureSegment()
        {
            // Arrange
            string             odataPath          = "GetRoutingCustomerById()";
            string             expectedText       = "Default.Container.GetRoutingCustomerById";
            IEdmEntitySet      expectedSet        = _model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "RoutingCustomers");
            IEdmFunctionImport expectedEdmElement = _model.EntityContainers().First().FunctionImports().SingleOrDefault(s => s.Name == "GetRoutingCustomerById");

            // 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);
            ActionPathSegment action = Assert.IsType <ActionPathSegment>(segment);

            Assert.Same(expectedEdmElement, action.Action);
        }
Пример #13
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);
        }
Пример #14
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 CanParseKeyUrl()
        {
            // Arrange
            string        testUrl      = "http://myservice/Customers(112)";
            string        expectedText = "112";
            IEdmEntitySet expectedSet  = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "Customers");
            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.IsType <KeyValuePathSegment>(segment);
            Assert.Same(expectedSet, segment.EntitySet);
            Assert.Same(expectedSet.ElementType, segment.EdmType);
        }
        public void CanParseCastEntitySegment()
        {
            // Arrange
            string         testUrl      = "http://myservice/Customers(100)/System.Web.Http.OData.Routing.VIP";
            string         expectedText = "System.Web.Http.OData.Routing.VIP";
            IEdmEntitySet  expectedSet  = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "Customers");
            IEdmEntityType expectedType = _parser.Model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(s => s.Name == "VIP");
            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(expectedType, segment.EdmType);
        }
Пример #17
0
        public void CanParseActionBoundToCollectionSegment()
        {
            // Arrange
            string             odataPath          = "RoutingCustomers/System.Web.Http.OData.Routing.VIP/GetMostProfitable";
            string             expectedText       = "Default.Container.GetMostProfitable";
            IEdmFunctionImport expectedEdmElement = _model.EntityContainers().First().FunctionImports().SingleOrDefault(p => p.Name == "GetMostProfitable");
            IEdmEntitySet      expectedSet        = _model.EntityContainers().First().EntitySets().SingleOrDefault(e => e.Name == "RoutingCustomers");
            IEdmType           expectedType       = expectedEdmElement.ReturnType.Definition;

            // 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.Same(expectedType, path.EdmType);
            ActionPathSegment action = Assert.IsType <ActionPathSegment>(segment);

            Assert.Same(expectedEdmElement, action.Action);
        }
        public void CanParsePropertySegment()
        {
            // Arrange
            string       testUrl            = "http://myservice/Customers(112)/Name";
            string       expectedText       = "Name";
            IEdmProperty expectedEdmElement = _parser.Model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(e => e.Name == "Customer").Properties().SingleOrDefault(p => p.Name == "Name");
            IEdmType     expectedType       = expectedEdmElement.Type.Definition;
            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.Null(segment.EntitySet);
            PropertyAccessPathSegment propertyAccess = Assert.IsType <PropertyAccessPathSegment>(segment);

            Assert.Same(expectedEdmElement, propertyAccess.Property);
        }
        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 CanParseRootProcedureSegment()
        {
            // Arrange
            string             testUrl            = "http://myservice/GetCustomerById()";
            string             expectedText       = "Default.Container.GetCustomerById";
            IEdmEntitySet      expectedSet        = _parser.Model.EntityContainers().First().EntitySets().SingleOrDefault(s => s.Name == "Customers");
            IEdmFunctionImport expectedEdmElement = _parser.Model.EntityContainers().First().FunctionImports().SingleOrDefault(s => s.Name == "GetCustomerById");
            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);
            ActionPathSegment action = Assert.IsType <ActionPathSegment>(segment);

            Assert.Same(expectedEdmElement, action.Action);
        }
        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);
        }