当前位置: 首页>>代码示例>>C#>>正文


C# ODataEntityDeserializer.ApplyNavigationProperty方法代码示例

本文整理汇总了C#中System.Web.OData.Formatter.Deserialization.ODataEntityDeserializer.ApplyNavigationProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ODataEntityDeserializer.ApplyNavigationProperty方法的具体用法?C# ODataEntityDeserializer.ApplyNavigationProperty怎么用?C# ODataEntityDeserializer.ApplyNavigationProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.OData.Formatter.Deserialization.ODataEntityDeserializer的用法示例。


在下文中一共展示了ODataEntityDeserializer.ApplyNavigationProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyNavigationProperty_Calls_ReadInlineOnEntry

        public void ApplyNavigationProperty_Calls_ReadInlineOnEntry()
        {
            // Arrange
            Mock<ODataEdmTypeDeserializer> supplierDeserializer = new Mock<ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Supplier" });
            navigationLink.NestedItems.Add(new ODataEntryWithNavigationLinks(new ODataEntry()));

            Product product = new Product();
            Supplier supplier = new Supplier { ID = 42 };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(supplierDeserializer.Object);
            supplierDeserializer
                .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _productEdmType.FindNavigationProperty("Supplier").Type, _readContext))
                .Returns(supplier).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(product, navigationLink, _productEdmType, _readContext);

            // Assert
            supplierDeserializer.Verify();
            Assert.Equal(supplier, product.Supplier);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:24,代码来源:ODataEntityDeserializerTests.cs

示例2: ApplyNavigationProperty_Calls_ReadInlineOnFeed

        public void ApplyNavigationProperty_Calls_ReadInlineOnFeed()
        {
            // Arrange
            IEdmCollectionTypeReference productsType = new EdmCollectionTypeReference(new EdmCollectionType(_productEdmType));
            Mock<ODataEdmTypeDeserializer> productsDeserializer = new Mock<ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" });
            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));

            Supplier supplier = new Supplier();
            IEnumerable products = new[] { new Product { ID = 42 } };

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(productsDeserializer.Object);
            productsDeserializer
                .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _supplierEdmType.FindNavigationProperty("Products").Type, _readContext))
                .Returns(products).Verifiable();

            // Act
            deserializer.ApplyNavigationProperty(supplier, navigationLink, _supplierEdmType, _readContext);

            // Assert
            productsDeserializer.Verify();
            Assert.Equal(1, supplier.Products.Count());
            Assert.Equal(42, supplier.Products.First().ID);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:26,代码来源:ODataEntityDeserializerTests.cs

示例3: ApplyNavigationProperty_ThrowsODataException_WhenPatchingCollectionNavigationProperty

        public void ApplyNavigationProperty_ThrowsODataException_WhenPatchingCollectionNavigationProperty()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" });
            navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));
            _readContext.ResourceType = typeof(Delta<Supplier>);

            Assert.Throws<ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _supplierEdmType, _readContext),
                "Cannot apply PATCH to navigation property 'Products' on entity type 'ODataDemo.Supplier'.");
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:11,代码来源:ODataEntityDeserializerTests.cs

示例4: ApplyNavigationProperty_ThrowsODataException_NavigationPropertyNotfound

        public void ApplyNavigationProperty_ThrowsODataException_NavigationPropertyNotfound()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "SomeProperty" });

            Assert.Throws<ODataException>(
                () => deserializer.ApplyNavigationProperty(42, navigationLink, _productEdmType, _readContext),
                "Cannot find navigation property 'SomeProperty' on the entity type 'ODataDemo.Product'.");
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:9,代码来源:ODataEntityDeserializerTests.cs

示例5: ApplyNavigationProperty_ThrowsArgumentNull_EntityResource

 public void ApplyNavigationProperty_ThrowsArgumentNull_EntityResource()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink());
     Assert.ThrowsArgumentNull(
         () => deserializer.ApplyNavigationProperty(entityResource: null, navigationLinkWrapper: navigationLink,
             entityType: _productEdmType, readContext: _readContext),
         "entityResource");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:9,代码来源:ODataEntityDeserializerTests.cs

示例6: ApplyNavigationProperty_ThrowsArgumentNull_NavigationLinkWrapper

 public void ApplyNavigationProperty_ThrowsArgumentNull_NavigationLinkWrapper()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.ApplyNavigationProperty(42, navigationLinkWrapper: null, entityType: _productEdmType,
             readContext: _readContext),
         "navigationLinkWrapper");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:8,代码来源:ODataEntityDeserializerTests.cs


注:本文中的System.Web.OData.Formatter.Deserialization.ODataEntityDeserializer.ApplyNavigationProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。