本文整理汇总了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);
}
示例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);
}
示例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'.");
}
示例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'.");
}
示例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");
}
示例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");
}