Esempio n. 1
0
        public void ODataPathSegmentHandler_Handles_KeySegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityType customer = new EdmEntityType("NS", "Customer");

            customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String));

            EdmEntityContainer           entityContainer = new EdmEntityContainer("NS", "Default");
            EdmEntitySet                 customers       = entityContainer.AddEntitySet("Customers", customer);
            IDictionary <string, object> keys            = new Dictionary <string, object>
            {
                { "Id", "abc" }
            };

            KeySegment segment = new KeySegment(keys, customer, customers);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("('abc')", handler.PathLiteral);
            Assert.Same(customers, handler.NavigationSource);
        }
Esempio n. 2
0
        public override void HandleWith(PathSegmentHandler handler)
        {
            ODataPathSegmentHandler pathSegmentHandler = handler as ODataPathSegmentHandler;

            if (pathSegmentHandler != null)
            {
                pathSegmentHandler.Handle(this);
            }
        }
Esempio n. 3
0
        public void ODataPathSegmentHandler_Handles_CountSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            // Act
            handler.Handle(CountSegment.Instance);

            // Assert
            Assert.Equal("$count", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 4
0
        public void ODataPathSegmentHandler_Handles_DynamicPathSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();
            DynamicPathSegment      segment = new DynamicPathSegment("any");

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("any", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 5
0
        public void ODataPathSegmentHandler_Handles_PathTemplateSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();
            PathTemplateSegment     segment = new PathTemplateSegment("{any}");

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("{any}", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 6
0
        public void ODataPathSegmentHandler_Handles_KeySegment_AfterNavigationProperty()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityType customer = new EdmEntityType("NS", "Customer");

            customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

            EdmEntityType order = new EdmEntityType("NS", "order");

            order.AddKeys(order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

            IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name               = "Orders",
                Target             = order,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            NavigationPropertyLinkSegment segment1 = new NavigationPropertyLinkSegment(ordersNavProperty, null);

            EdmEntityContainer           entityContainer = new EdmEntityContainer("NS", "Default");
            EdmEntitySet                 orders          = entityContainer.AddEntitySet("Orders", order);
            IDictionary <string, object> keys            = new Dictionary <string, object>
            {
                { "Id", 42 }
            };

            KeySegment segment2 = new KeySegment(keys, order, orders);

            // Act
            handler.Handle(segment1);
            handler.Handle(segment2);

            // Assert
            Assert.Equal("Orders(42)/$ref", handler.PathLiteral);
            Assert.Same(orders, handler.NavigationSource);
        }
Esempio n. 7
0
        public void ODataPathSegmentHandler_Handles_ValueSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();
            IEdmType     intType            = EdmCoreModel.Instance.GetInt32(false).Definition;
            ValueSegment segment            = new ValueSegment(intType);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("$value", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 8
0
        public void ODataPathSegmentHandler_Handles_ActionSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();
            IEdmTypeReference       intType = EdmCoreModel.Instance.GetInt32(false);
            IEdmAction       action         = new EdmAction("NS", "action", intType);
            OperationSegment segment        = new OperationSegment(action, null);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("NS.action", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 9
0
        public void ODataPathSegmentHandler_Handles_EntitySetSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler         = new ODataPathSegmentHandler();
            EdmEntityContainer      entityContainer = new EdmEntityContainer("NS", "Default");
            EdmEntityType           customer        = new EdmEntityType("NS", "Customer");
            EdmEntitySet            customers       = entityContainer.AddEntitySet("Customers", customer);
            EntitySetSegment        segment         = new EntitySetSegment(customers);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("Customers", handler.PathLiteral);
            Assert.Same(customers, handler.NavigationSource);
        }
Esempio n. 10
0
        public void ODataPathSegmentHandler_Handles_PropertySegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityType          customer = new EdmEntityType("NS", "Customer");
            IEdmStructuralProperty property = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            PropertySegment        segment  = new PropertySegment(property);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("Name", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 11
0
        public void ODataPathSegmentHandler_Handles_SingletonSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default");
            EdmEntityType      customer        = new EdmEntityType("NS", "Customer");
            EdmSingleton       me      = entityContainer.AddSingleton("me", customer);
            SingletonSegment   segment = new SingletonSegment(me);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("me", handler.PathLiteral);
            Assert.Same(me, handler.NavigationSource);
        }
Esempio n. 12
0
        public void ODataPathSegmentHandler_Handles_FunctionImportSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();
            IEdmTypeReference       intType = EdmCoreModel.Instance.GetInt32(false);

            EdmEntityContainer     entityContainer = new EdmEntityContainer("NS", "Default");
            IEdmFunction           function        = new EdmFunction("NS", "function", intType);
            IEdmFunctionImport     functionImport  = new EdmFunctionImport(entityContainer, "function", function);
            OperationImportSegment segment         = new OperationImportSegment(functionImport, null);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("function()", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }
Esempio n. 13
0
        public void ODataPathSegmentHandler_Handles_NavigationPropertyLinkSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityType          customer          = new EdmEntityType("NS", "customer");
            EdmEntityType          order             = new EdmEntityType("NS", "order");
            IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name               = "Orders",
                Target             = order,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            NavigationPropertyLinkSegment segment = new NavigationPropertyLinkSegment(ordersNavProperty, null);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("Orders/$ref", handler.PathLiteral);
            Assert.Null(handler.NavigationSource);
        }