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


C# Deserialization.ODataEntityDeserializer类代码示例

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


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


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