本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.CreateODataFeed方法的典型用法代码示例。如果您正苦于以下问题:C# ODataFeedSerializer.CreateODataFeed方法的具体用法?C# ODataFeedSerializer.CreateODataFeed怎么用?C# ODataFeedSerializer.CreateODataFeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer
的用法示例。
在下文中一共展示了ODataFeedSerializer.CreateODataFeed方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference()), isNullable: false);
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true);
IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First();
EntityInstanceContext entity = new EntityInstanceContext
{
SerializerContext = new ODataSerializerContext { EntitySet = model.Customers, Model = model.Model }
};
ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, ordersProperty);
TruncatedCollection<Order> orders = new TruncatedCollection<Order>(new[] { new Order(), new Order() }, pageSize: 1);
Mock<EntitySetLinkBuilderAnnotation> linkBuilder = new Mock<EntitySetLinkBuilderAnnotation>();
linkBuilder.Setup(l => l.BuildNavigationLink(entity, ordersProperty, ODataMetadataLevel.Default)).Returns(new Uri("http://navigation-link/"));
model.Model.SetEntitySetLinkBuilder(model.Customers, linkBuilder.Object);
model.Model.SetEntitySetLinkBuilder(model.Orders, new EntitySetLinkBuilderAnnotation());
// Act
ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext);
// Assert
Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri);
}
示例2: CreateODataFeed_Sets_FeedSelfLink
public void CreateODataFeed_Sets_FeedSelfLink()
{
// Arrange
var feedInstance = new object[0];
ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Model = _model, Request = new HttpRequestMessage() };
writeContext.Url = new UrlHelper(writeContext.Request);
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Uri feedSelfLink = new Uri("http://feed_self_link/");
EntitySetLinkBuilderAnnotation linkBuilder = new MockEntitySetLinkBuilderAnnotation
{
FeedSelfLinkBuilder = (context) =>
{
Assert.Equal(_customerSet, context.EntitySet);
Assert.Equal(feedInstance, context.FeedInstance);
Assert.Equal(writeContext.Request, context.Request);
Assert.Equal(writeContext.Url, context.Url);
return feedSelfLink;
}
};
_model.SetEntitySetLinkBuilder(_customerSet, linkBuilder);
// Act
ODataFeed feed = serializer.CreateODataFeed(feedInstance, _customersType, writeContext);
// Assert
AtomFeedMetadata feedMetadata = feed.GetAnnotation<AtomFeedMetadata>();
Assert.Equal(feedSelfLink, feedMetadata.SelfLink.Href);
Assert.Equal("self", feedMetadata.SelfLink.Relation);
}
示例3: CreateODataFeed_Ignores_InlineCount_ForInnerFeeds
public void CreateODataFeed_Ignores_InlineCount_ForInnerFeeds()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
HttpRequestMessage request = new HttpRequestMessage();
request.SetInlineCount(42);
var result = new object[0];
IEdmNavigationProperty navProp = new Mock<IEdmNavigationProperty>().Object;
SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true);
EntityInstanceContext entity = new EntityInstanceContext
{
SerializerContext = new ODataSerializerContext { Request = request, EntitySet = _customerSet }
};
ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, navProp);
// Act
ODataFeed feed = serializer.CreateODataFeed(result, _customersType, nestedContext);
// Assert
Assert.Null(feed.Count);
}
示例4: CreateODataFeed_Sets_NextPageLinkFromContext
public void CreateODataFeed_Sets_NextPageLinkFromContext()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Uri expectedNextLink = new Uri("http://nextlink.com");
HttpRequestMessage request = new HttpRequestMessage();
request.SetNextPageLink(expectedNextLink);
var result = new object[0];
// Act
ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request });
// Assert
Assert.Equal(expectedNextLink, feed.NextPageLink);
}
示例5: CreateODataFeed_Sets_InlineCountFromContext
public void CreateODataFeed_Sets_InlineCountFromContext()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
long expectedInlineCount = 1000;
HttpRequestMessage request = new HttpRequestMessage();
request.SetInlineCount(expectedInlineCount);
var result = new object[0];
// Act
ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request });
// Assert
Assert.Equal(expectedInlineCount, feed.Count);
}
示例6: CreateODataFeed_Sets_NextPageLinkForPageResult
public void CreateODataFeed_Sets_NextPageLinkForPageResult()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Uri expectedNextLink = new Uri("http://nextlink.com");
long expectedInlineCount = 1000;
var result = new PageResult<Customer>(_customers, expectedNextLink, expectedInlineCount);
// Act
ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext());
// Assert
Assert.Equal(expectedNextLink, feed.NextPageLink);
}
示例7: CreateODataFeed_Ignores_InlineCount_ForInnerFeeds
public void CreateODataFeed_Ignores_InlineCount_ForInnerFeeds()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(_customersType, new DefaultODataSerializerProvider());
HttpRequestMessage request = new HttpRequestMessage();
request.SetInlineCount(42);
var result = new object[0];
// Act
ODataFeed feed = serializer.CreateODataFeed(result, new ODataSerializerContext { Request = request, IsNested = true });
// Assert
Assert.Null(feed.Count);
}
示例8: CreateODataFeed_Ignores_NextPageLink_ForInnerFeeds
public void CreateODataFeed_Ignores_NextPageLink_ForInnerFeeds()
{
// Arrange
ODataFeedSerializer serializer = new ODataFeedSerializer(_customersType, new DefaultODataSerializerProvider());
Uri nextLink = new Uri("http://somelink");
HttpRequestMessage request = new HttpRequestMessage();
request.SetNextPageLink(nextLink);
var result = new object[0];
// Act
ODataFeed feed = serializer.CreateODataFeed(result, new ODataSerializerContext { Request = request, IsNested = true });
// Assert
Assert.Null(feed.NextPageLink);
}