本文整理匯總了C#中System.Web.Http.OData.Formatter.Deserialization.ODataEntityDeserializer.Read方法的典型用法代碼示例。如果您正苦於以下問題:C# ODataEntityDeserializer.Read方法的具體用法?C# ODataEntityDeserializer.Read怎麽用?C# ODataEntityDeserializer.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.Http.OData.Formatter.Deserialization.ODataEntityDeserializer
的用法示例。
在下文中一共展示了ODataEntityDeserializer.Read方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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");
}
示例2: Read_ThrowsArgumentNull_ReadContext
public void Read_ThrowsArgumentNull_ReadContext()
{
var deserializer = new ODataEntityDeserializer(_productEdmType, _deserializerProvider);
Assert.ThrowsArgumentNull(
() => deserializer.Read(messageReader: ODataTestUtil.GetMockODataMessageReader(), readContext: null),
"readContext");
}
示例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 could not be found from the OData path. The related entity set is required to deserialize the payload.");
}
示例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.");
}
示例5: 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.");
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: Read_PatchMode_PatchKeyModeIsThrow
public void Read_PatchMode_PatchKeyModeIsThrow()
{
IEdmEntityType supplierEntityType = EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;
_readContext.IsPatchMode = true;
_readContext.PatchKeyMode = PatchKeyMode.Throw;
ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_supplierEdmType, _deserializerProvider);
Assert.Throws<InvalidOperationException>(
() => deserializer.Read(GetODataMessageReader(GetODataMessage(BaselineResource.SuppliersPatchData), _edmModel), _readContext),
"Cannot apply PATCH on key property 'ID' on entity type 'ODataDemo.Supplier' when 'PatchKeyMode' is 'Throw'.");
}
示例11: 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);
}
示例12: Read_PatchMode
private void Read_PatchMode(string content, bool json)
{
IEdmEntityType supplierEntityType =
EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;
_readContext.ResourceType = typeof(Delta<Supplier>);
ODataEntityDeserializer deserializer =
new ODataEntityDeserializer(_deserializerProvider);
Delta<Supplier> supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
typeof(Delta<Supplier>), _readContext) as Delta<Supplier>;
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);
}
示例13: ReadFromStreamAsync_ComplexTypeAndInlineData
private void ReadFromStreamAsync_ComplexTypeAndInlineData(string content, bool json)
{
IEdmEntityType supplierEntityType =
EdmTestHelpers.GetModel().FindType("ODataDemo.Supplier") as IEdmEntityType;
ODataEntityDeserializer deserializer = new ODataEntityDeserializer(_deserializerProvider);
Supplier supplier = deserializer.Read(GetODataMessageReader(GetODataMessage(content, json), _edmModel),
typeof(Supplier), _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);
}