• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Deserialization.ODataEntityDeserializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ODataEntityDeserializer类属于System.Web.OData.Formatter.Deserialization命名空间,在下文中一共展示了ODataEntityDeserializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Read_ThrowsArgumentNull_ReadContext

 public void Read_ThrowsArgumentNull_ReadContext()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.Read(messageReader: ODataTestUtil.GetMockODataMessageReader(), type: typeof(Product), readContext: null),
         "readContext");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:7,代码来源:ODataEntityDeserializerTests.cs


示例2: Read_ThrowsArgumentNull_MessageReader

 public void Read_ThrowsArgumentNull_MessageReader()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.Read(messageReader: null, type: typeof(Product), readContext: _readContext),
         "messageReader");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:7,代码来源:ODataEntityDeserializerTests.cs


示例3: Read_ThrowsArgument_EntitysetMissing

 public void Read_ThrowsArgument_EntitysetMissing()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.Throws<SerializationException>(
         () => deserializer.Read(ODataTestUtil.GetMockODataMessageReader(), typeof(Product), new ODataDeserializerContext { Path = new ODataPath() }),
         "The related entity set or singleton cannot be found from the OData path. The related entity set or singleton is required to deserialize the payload.");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:7,代码来源:ODataEntityDeserializerTests.cs


示例4: Read_ThrowsArgument_ODataPathMissing

 public void Read_ThrowsArgument_ODataPathMissing()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgument(
         () => deserializer.Read(ODataTestUtil.GetMockODataMessageReader(), typeof(Product), new ODataDeserializerContext()),
         "readContext",
         "The operation cannot be completed because no ODataPath is available for the request.");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:8,代码来源:ODataEntityDeserializerTests.cs


示例5: DefaultODataDeserializerProvider

 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultODataDeserializerProvider"/> class.
 /// </summary>
 public DefaultODataDeserializerProvider()
 {
     _actionPayloadDeserializer = new ODataActionPayloadDeserializer(this);
     _entityDeserializer = new ODataEntityDeserializer(this);
     _feedDeserializer = new ODataFeedDeserializer(this);
     _collectionDeserializer = new ODataCollectionDeserializer(this);
     _complexDeserializer = new ODataComplexTypeDeserializer(this);
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:11,代码来源:DefaultODataDeserializerProvider.cs


示例6: CanDeserializerSingletonPayloadFromStream

        public void CanDeserializerSingletonPayloadFromStream()
        {
            // Arrange
            const string payload = "{" +
                "\"@odata.context\":\"http://localhost/odata/$metadata#CEO\"," +
                "\"EmployeeId\":789," +
                "\"EmployeeName\":\"John Hark\"}";

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);

            // Act
            EmployeeModel employee = deserializer.Read(
                GetODataMessageReader(payload),
                typeof(EmployeeModel),
                _readContext) as EmployeeModel;

            // Assert
            Assert.NotNull(employee);
            Assert.Equal(789, employee.EmployeeId);
            Assert.Equal("John Hark", employee.EmployeeName);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:21,代码来源:ODataSingletonDeserializerTest.cs


示例7: ApplyStructuralProperty_ThrowsArgumentNull_StructuralProperty

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


示例8: ApplyStructuralProperties_ThrowsArgumentNull_entryWrapper

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


示例9: ReadEntry_CanReadDynamicPropertiesForInheritanceOpenEntityType

        public void ReadEntry_CanReadDynamicPropertiesForInheritanceOpenEntityType()
        {
            // Arrange
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntityType<SimpleOpenCustomer>();
            builder.EnumType<SimpleEnum>();
            IEdmModel model = builder.GetEdmModel();

            IEdmEntityTypeReference vipCustomerTypeReference = model.GetEdmTypeReference(typeof(SimpleVipCustomer)).AsEntity();

            var deserializerProvider = new DefaultODataDeserializerProvider();
            var deserializer = new ODataEntityDeserializer(deserializerProvider);

            ODataEntry odataEntry = new ODataEntry
            {
                Properties = new[]
                {
                    // declared properties
                    new ODataProperty { Name = "CustomerId", Value = 121 },
                    new ODataProperty { Name = "Name", Value = "VipName #121" },
                    new ODataProperty { Name = "VipNum", Value = "Vip Num 001" },

                    // dynamic properties
                    new ODataProperty { Name = "GuidProperty", Value = new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA") },
                },
                TypeName = typeof(SimpleVipCustomer).FullName
            };

            ODataDeserializerContext readContext = new ODataDeserializerContext()
            {
                Model = model
            };

            ODataEntryWithNavigationLinks entry = new ODataEntryWithNavigationLinks(odataEntry);

            // Act
            SimpleVipCustomer customer = deserializer.ReadEntry(entry, vipCustomerTypeReference, readContext)
                as SimpleVipCustomer;

            // Assert
            Assert.NotNull(customer);

            // Verify the declared properties
            Assert.Equal(121, customer.CustomerId);
            Assert.Equal("VipName #121", customer.Name);
            Assert.Equal("Vip Num 001", customer.VipNum);

            // Verify the dynamic properties
            Assert.NotNull(customer.CustomerProperties);
            Assert.Equal(1, customer.CustomerProperties.Count());
            Assert.Equal(new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA"), customer.CustomerProperties["GuidProperty"]);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:52,代码来源:ODataEntityDeserializerTests.cs


示例10: ReadInline_Throws_ArgumentMustBeOfType

 public void ReadInline_Throws_ArgumentMustBeOfType()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.ThrowsArgument(
         () => deserializer.ReadInline(item: 42, edmType: _productEdmType, readContext: new ODataDeserializerContext()),
         "item",
         "The argument must be of type 'ODataEntry'");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:8,代码来源:ODataEntityDeserializerTests.cs


示例11: CreateEntityResource_ThrowsODataException_MappingDoesNotContainEntityType

 public void CreateEntityResource_ThrowsODataException_MappingDoesNotContainEntityType()
 {
     var deserializer = new ODataEntityDeserializer(_deserializerProvider);
     Assert.Throws<ODataException>(
         () => deserializer.CreateEntityResource(_productEdmType, new ODataDeserializerContext { Model = EdmCoreModel.Instance }),
         "The provided mapping does not contain an entry for the entity type 'ODataDemo.Product'.");
 }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:7,代码来源:ODataEntityDeserializerTests.cs


示例12: ReadFromStreamAsync_ComplexTypeAndInlineData

        public void ReadFromStreamAsync_ComplexTypeAndInlineData()
        {
            // Arrange
            string content = Resources.SupplierRequestEntry;
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);

            var readContext = new ODataDeserializerContext
            {
                Path = new ODataPath(new EntitySetPathSegment(_edmModel.EntityContainer.FindEntitySet("Suppliers"))),
                Model = _edmModel,
                ResourceType = typeof(Supplier)
            };

            // Act
            Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                typeof(Supplier), readContext) as Supplier;

            // Assert
            Assert.Equal(supplier.Name, "Supplier Name");

            Assert.NotNull(supplier.Products);
            Assert.Equal(6, supplier.Products.Count);
            Assert.Equal("soda", supplier.Products.ToList()[1].Name);

            Assert.NotNull(supplier.Address);
            Assert.Equal("Supplier City", supplier.Address.City);
            Assert.Equal("123456", supplier.Address.ZipCode);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:31,代码来源:ODataEntityDeserializerTests.cs


示例13: Read_PatchMode

        public void Read_PatchMode()
        {
            // Arrange
            string content = Resources.SupplierPatch;
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            var readContext = new ODataDeserializerContext
            {
                Path = new ODataPath(new EntitySetPathSegment(_edmModel.EntityContainer.FindEntitySet("Suppliers"))),
                Model = _edmModel,
                ResourceType = typeof(Delta<Supplier>)
            };

            ODataEntityDeserializer deserializer =
                new ODataEntityDeserializer(_deserializerProvider);

            // Act
            Delta<Supplier> supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                typeof(Delta<Supplier>), readContext) as Delta<Supplier>;

            // Assert
            Assert.NotNull(supplier);
            Assert.Equal(supplier.GetChangedPropertyNames(), new string[] { "ID", "Name", "Address" });

            Assert.Equal((supplier as dynamic).Name, "Supplier Name");
            Assert.Equal("Supplier City", (supplier as dynamic).Address.City);
            Assert.Equal("123456", (supplier as dynamic).Address.ZipCode);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:29,代码来源:ODataEntityDeserializerTests.cs


示例14: 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


示例15: 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


示例16: CreateEntityResource_ThrowsArgumentNull_ReadContext

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


示例17: 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


示例18: CreateEntityResource_CreatesT_IfNotPatchMode

        public void CreateEntityResource_CreatesT_IfNotPatchMode()
        {
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model = _readContext.Model,
                ResourceType = typeof(Product)
            };

            Assert.IsType<Product>(deserializer.CreateEntityResource(_productEdmType, readContext));
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:11,代码来源:ODataEntityDeserializerTests.cs


示例19: CreateEntityResource_CreatesEdmEntityObject_IfTypeLessMode

        public void CreateEntityResource_CreatesEdmEntityObject_IfTypeLessMode()
        {
            // Arrange
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model = _readContext.Model,
                ResourceType = typeof(IEdmObject)
            };

            // Act
            var result = deserializer.CreateEntityResource(_productEdmType, readContext);

            // Assert
            EdmEntityObject resource = Assert.IsType<EdmEntityObject>(result);
            Assert.Equal(_productEdmType, resource.GetEdmType(), new EdmTypeReferenceEqualityComparer());
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:17,代码来源:ODataEntityDeserializerTests.cs


示例20: CreateEntityResource_CreatesDeltaWith_ExpectedUpdatableProperties

        public void CreateEntityResource_CreatesDeltaWith_ExpectedUpdatableProperties()
        {
            // Arrange
            var deserializer = new ODataEntityDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model = _readContext.Model,
                ResourceType = typeof(Delta<Product>)
            };
            var structuralProperties = _productEdmType.StructuralProperties().Select(p => p.Name);

            // Act
            Delta<Product> resource = deserializer.CreateEntityResource(_productEdmType, readContext) as Delta<Product>;

            // Assert
            Assert.NotNull(resource);
            Assert.Equal(structuralProperties, resource.GetUnchangedPropertyNames());
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:18,代码来源:ODataEntityDeserializerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.ODataSerializerContext类代码示例发布时间:2022-05-26
下一篇:
C# Deserialization.ODataDeserializerContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap