當前位置: 首頁>>代碼示例>>C#>>正文


C# Deserialization.ODataEntityDeserializer類代碼示例

本文整理匯總了C#中System.Web.Http.OData.Formatter.Deserialization.ODataEntityDeserializer的典型用法代碼示例。如果您正苦於以下問題:C# ODataEntityDeserializer類的具體用法?C# ODataEntityDeserializer怎麽用?C# ODataEntityDeserializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ODataEntityDeserializer類屬於System.Web.Http.OData.Formatter.Deserialization命名空間,在下文中一共展示了ODataEntityDeserializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Read_ThrowsArgumentNull_MessageReader

 public void Read_ThrowsArgumentNull_MessageReader()
 {
     var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.Read(messageReader: null, readContext: _readContext),
         "messageReader");
 }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:7,代碼來源:ODataEntityDeserializerTests.cs

示例2: 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 could not be found from the OData path. The related entity set is required to deserialize the payload.");
 }
開發者ID:normalian,項目名稱:aspnetwebstack,代碼行數:7,代碼來源:ODataEntityDeserializerTests.cs

示例3: Read_ThrowsArgumentNull_ReadContext

 public void Read_ThrowsArgumentNull_ReadContext()
 {
     var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.Read(messageReader: ODataTestUtil.GetMockODataMessageReader(), readContext: null),
         "readContext");
 }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:7,代碼來源:ODataEntityDeserializerTests.cs

示例4: Read_ThrowsArgument_ODataPathMissing

 public void Read_ThrowsArgument_ODataPathMissing()
 {
     var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
     Assert.ThrowsArgument(
         () => deserializer.Read(ODataTestUtil.GetMockODataMessageReader(), new ODataDeserializerContext()),
         "readContext",
         "The operation cannot be completed because no ODataPath is available for the request.");
 }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數: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:quentez,項目名稱:aspnetwebstack,代碼行數:11,代碼來源:DefaultODataDeserializerProvider.cs

示例6: Read_Throws_On_UnknownEntityType

        public void Read_Throws_On_UnknownEntityType()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);

            Assert.Throws<ODataException>(
                () => deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersInsertData), _edmModel), _readContext),
                "An entry with type 'ODataDemo.Supplier' was found, but it is not assignable to the expected type 'ODataDemo.Product'. The type specified in the entry must be equal to either the expected type or a derived type.");
        }
開發者ID:Swethach,項目名稱:aspnetwebstack,代碼行數:10,代碼來源:ODataEntityDeserializerTests.cs

示例7: ReadFromStreamAsync

        public void ReadFromStreamAsync()
        {
            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
            Product product = deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.ProductInsertData), _edmModel), _readContext) as Product;

            Assert.Equal(product.ID, 0);
            Assert.Equal(product.Rating, 4);
            Assert.Equal(product.Price, 2.5m);
            Assert.Equal(product.ReleaseDate, new DateTime(1992, 1, 1, 0, 0, 0));
            Assert.Null(product.DiscontinuedDate);
        }
開發者ID:marojeri,項目名稱:aspnetwebstack,代碼行數:11,代碼來源:ODataEntityDeserializerTests.cs

示例8: ReadFromStreamAsync

        private void ReadFromStreamAsync(string content, bool json)
        {
            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
            Product product = deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
                _readContext) as Product;

            Assert.Equal(product.ID, 0);
            Assert.Equal(product.Rating, 4);
            Assert.Equal(product.Price, 2.5m);
            Assert.Equal(product.ReleaseDate, new DateTime(1992, 1, 1, 0, 0, 0));
            Assert.Null(product.DiscontinuedDate);
        }
開發者ID:naulizzang,項目名稱:aspnetwebstack,代碼行數:12,代碼來源:ODataEntityDeserializerTests.cs

示例9: Read_PatchMode

        public void Read_PatchMode()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;
            _readContext.IsPatchMode = true;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);
            Delta<Supplier> supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersPatchData), _edmModel), _readContext) as Delta<Supplier>;

            Assert.NotNull(supplier);
            Assert.Equal(supplier.GetChangedPropertyNames(), new string[] { "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:marojeri,項目名稱:aspnetwebstack,代碼行數:15,代碼來源:ODataEntityDeserializerTests.cs

示例10: ReadFromStreamAsync_ComplexTypeAndInlineData

        public void ReadFromStreamAsync_ComplexTypeAndInlineData()
        {
            IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);
            Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersInsertData), _edmModel), _readContext) as Supplier;

            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:marojeri,項目名稱:aspnetwebstack,代碼行數:17,代碼來源:ODataEntityDeserializerTests.cs

示例11: ReadEntry_ThrowsSerializationException_TypeCannotBeDeserialized

        public void ReadEntry_ThrowsSerializationException_TypeCannotBeDeserialized()
        {
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns<ODataEdmTypeDeserializer>(null);
            var deserializer = new ODataEntityDeserializer(_productEdmType, deserializerProvider.Object);
            ODataEntryWithNavigationLinks entry = new ODataEntryWithNavigationLinks(new ODataEntry { TypeName = _supplierEdmType.FullName() });

            Assert.Throws<SerializationException>(
                () => deserializer.ReadEntry(entry, _readContext),
                "'ODataDemo.Supplier' cannot be deserialized using the ODataMediaTypeFormatter.");
        }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:11,代碼來源:ODataEntityDeserializerTests.cs

示例12: CreateEntityResource_ThrowsArgumentNull_ReadContext

 public void CreateEntityResource_ThrowsArgumentNull_ReadContext()
 {
     var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
     Assert.ThrowsArgumentNull(
         () => deserializer.CreateEntityResource(readContext: null),
         "readContext");
 }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:7,代碼來源:ODataEntityDeserializerTests.cs

示例13: ReadEntry_DispatchesToRightDeserializer_IfEntityTypeNameIsDifferent

        public void ReadEntry_DispatchesToRightDeserializer_IfEntityTypeNameIsDifferent()
        {
            // Arrange
            Mock<ODataEdmTypeDeserializer> supplierDeserializer = new Mock<ODataEdmTypeDeserializer>(_supplierEdmType, ODataPayloadKind.Entry);
            Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
            var deserializer = new ODataEntityDeserializer(_productEdmType, deserializerProvider.Object);
            ODataEntryWithNavigationLinks entry = new ODataEntryWithNavigationLinks(new ODataEntry { TypeName = _supplierEdmType.FullName() });

            deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(supplierDeserializer.Object);
            supplierDeserializer.Setup(d => d.ReadInline(entry, _readContext)).Returns(42).Verifiable();

            // Act
            object result = deserializer.ReadEntry(entry, _readContext);

            // Assert
            Assert.Equal(42, result);
            supplierDeserializer.Verify();
        }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:18,代碼來源:ODataEntityDeserializerTests.cs

示例14: Read_ThrowsOnUnknownEntityType

        private void Read_ThrowsOnUnknownEntityType(string content, bool json, string expectedMessage)
        {
            IEdmEntityType supplierEntityType =
                EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;

            ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);

            Assert.Throws<ODataException>(() => deserializer.Read(GetODataMessageReader(GetODataMessage(content, json),
                _edmModel), _readContext), expectedMessage);
        }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:10,代碼來源:ODataEntityDeserializerTests.cs

示例15: CreateEntityResource_ThrowsArgument_ModelMissingFromReadContext

 public void CreateEntityResource_ThrowsArgument_ModelMissingFromReadContext()
 {
     var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
     Assert.ThrowsArgument(
         () => deserializer.CreateEntityResource(new ODataDeserializerContext()),
         "readContext",
         "The EDM model is missing on the read context. The model is required on the read context to deserialize the payload.");
 }
開發者ID:brianly,項目名稱:aspnetwebstack,代碼行數:8,代碼來源:ODataEntityDeserializerTests.cs


注:本文中的System.Web.Http.OData.Formatter.Deserialization.ODataEntityDeserializer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。