本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer类的典型用法代码示例。如果您正苦于以下问题:C# ODataFeedSerializer类的具体用法?C# ODataFeedSerializer怎么用?C# ODataFeedSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataFeedSerializer类属于System.Web.Http.OData.Formatter.Serialization命名空间,在下文中一共展示了ODataFeedSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultODataSerializerProvider
/// <summary>
/// Initializes a new instance of the <see cref="DefaultODataSerializerProvider"/> class.
/// </summary>
public DefaultODataSerializerProvider()
{
_feedSerializer = new ODataFeedSerializer(this);
_collectionSerializer = new ODataCollectionSerializer(this);
_complexTypeSerializer = new ODataComplexTypeSerializer(this);
_entityTypeSerializer = new ODataEntityTypeSerializer(this);
}
示例2: WriteObjectInline_WritesEachEntityInstance
public void WriteObjectInline_WritesEachEntityInstance()
{
// Arrange
var mockSerializerProvider = new Mock<ODataSerializerProvider>(MockBehavior.Strict, _model);
var mockCustomerSerializer = new Mock<ODataSerializer>(MockBehavior.Strict, ODataPayloadKind.Entry);
var mockWriter = new Mock<ODataWriter>();
mockSerializerProvider
.Setup(p => p.CreateEdmTypeSerializer(_customersType.ElementType()))
.Returns(mockCustomerSerializer.Object);
mockCustomerSerializer
.Setup(s => s.WriteObjectInline(_customers[0], It.IsAny<ODataWriter>(), _writeContext))
.Verifiable();
mockCustomerSerializer
.Setup(s => s.WriteObjectInline(_customers[1], It.IsAny<ODataWriter>(), _writeContext))
.Verifiable();
mockWriter
.Setup(w => w.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
Assert.Equal("http://schemas.datacontract.org/2004/07/", feed.Id);
})
.Verifiable();
_serializer = new ODataFeedSerializer(_customersType, mockSerializerProvider.Object);
// Act
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
// Assert
mockSerializerProvider.Verify();
mockCustomerSerializer.Verify();
mockWriter.Verify();
}
示例3: WriteObject_ThrowsArgumentNull_MessageWriter
public void WriteObject_ThrowsArgumentNull_MessageWriter()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.ThrowsArgumentNull(
() => serializer.WriteObject(graph: null, type: null, messageWriter: null, writeContext: new ODataSerializerContext()),
"messageWriter");
}
示例4: WriteObject_ThrowsArgumentNull_WriteContext
public void WriteObject_ThrowsArgumentNull_WriteContext()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.ThrowsArgumentNull(
() => serializer.WriteObject(graph: null, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null),
"writeContext");
}
示例5: WriteObjectInline_WritesEachEntityInstance
public void WriteObjectInline_WritesEachEntityInstance()
{
// Arrange
SpyODataSerializer spy = new SpyODataSerializer(ODataPayloadKind.Entry);
ODataSerializerProvider provider = new FakeODataSerializerProvider(spy);
var mockWriter = new Mock<ODataWriter>();
mockWriter
.Setup(w => w.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
Assert.Equal("http://schemas.datacontract.org/2004/07/", feed.Id);
})
.Verifiable();
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
// Assert
WriteObjectInlineCall[] expectedWriteCalls = new WriteObjectInlineCall[]
{
new WriteObjectInlineCall { Graph = _customers[0], WriteContext = _writeContext },
new WriteObjectInlineCall { Graph = _customers[1], WriteContext = _writeContext }
};
AssertEqual(expectedWriteCalls, spy.WriteObjectInlineCalls);
mockWriter.Verify();
}
示例6: WriteObject_ThrowsEntitySetMissingDuringSerialization
public void WriteObject_ThrowsEntitySetMissingDuringSerialization()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.Throws<SerializationException>(
() => serializer.WriteObject(graph: null, type: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: new ODataSerializerContext()),
"The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.");
}
示例7: WriteObjectInline_WritesEachEntityInstance
public void WriteObjectInline_WritesEachEntityInstance()
{
// Arrange
Mock<ODataEntrySerializer> customerSerializer = new Mock<ODataEntrySerializer>(_customersType.ElementType(), ODataPayloadKind.Entry);
ODataSerializerProvider provider = ODataTestUtil.GetMockODataSerializerProvider(customerSerializer.Object);
var mockWriter = new Mock<ODataWriter>();
customerSerializer.Setup(s => s.WriteObjectInline(_customers[0], mockWriter.Object, _writeContext)).Verifiable();
customerSerializer.Setup(s => s.WriteObjectInline(_customers[1], mockWriter.Object, _writeContext)).Verifiable();
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
// Assert
customerSerializer.Verify();
}
示例8: WriteObjectInline_Sets_InlineCount_OnWriteStart
public void WriteObjectInline_Sets_InlineCount_OnWriteStart()
{
// Arrange
Mock<ODataEntrySerializer> customerSerializer = new Mock<ODataEntrySerializer>(_customersType.ElementType(), ODataPayloadKind.Entry);
ODataSerializerProvider provider = ODataTestUtil.GetMockODataSerializerProvider(customerSerializer.Object);
var mockWriter = new Mock<ODataWriter>();
Uri expectedNextLink = new Uri("http://nextlink.com");
long expectedInlineCount = 1000;
var result = new PageResult<Customer>(_customers, expectedNextLink, expectedInlineCount);
mockWriter
.Setup(m => m.WriteStart(It.Is<ODataFeed>(feed => feed.Count == expectedInlineCount)))
.Verifiable();
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(result, mockWriter.Object, _writeContext);
// Assert
mockWriter.Verify();
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: WriteObjectInline_Can_WriteCollectionOfIEdmObjects
public void WriteObjectInline_Can_WriteCollectionOfIEdmObjects()
{
// Arrange
IEdmTypeReference edmType = new EdmEntityTypeReference(new EdmEntityType("NS", "Name"), isNullable: false);
IEdmCollectionTypeReference feedType = new EdmCollectionTypeReference(new EdmCollectionType(edmType), isNullable: false);
Mock<IEdmObject> edmObject = new Mock<IEdmObject>();
edmObject.Setup(e => e.GetEdmType()).Returns(edmType);
var mockWriter = new Mock<ODataWriter>();
Mock<ODataEdmTypeSerializer> customSerializer = new Mock<ODataEdmTypeSerializer>(ODataPayloadKind.Entry);
customSerializer.Setup(s => s.WriteObjectInline(edmObject.Object, edmType, mockWriter.Object, _writeContext)).Verifiable();
Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
serializerProvider.Setup(s => s.GetEdmTypeSerializer(edmType)).Returns(customSerializer.Object);
ODataFeedSerializer serializer = new ODataFeedSerializer(serializerProvider.Object);
// Act
serializer.WriteObjectInline(new[] { edmObject.Object }, feedType, mockWriter.Object, _writeContext);
// Assert
customSerializer.Verify();
}
示例13: WriteObjectInline_Writes_InlineCountAndNextLink
public void WriteObjectInline_Writes_InlineCountAndNextLink()
{
// Arrange
SpyODataSerializer spy = new SpyODataSerializer(ODataPayloadKind.Entry);
ODataSerializerProvider provider = new FakeODataSerializerProvider(spy);
var mockWriter = new Mock<ODataWriter>();
Uri expectedNextLink = new Uri("http://nextlink.com");
long expectedInlineCount = 1000;
var result = new PageResult<Customer>(
_customers,
expectedNextLink,
expectedInlineCount
);
ODataFeed actualFeed = null;
mockWriter
.Setup(m => m.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
actualFeed = feed;
Assert.Equal(expectedInlineCount, feed.Count);
});
_serializer = new ODataFeedSerializer(_customersType, provider);
_serializer.WriteObjectInline(result, mockWriter.Object, _writeContext);
// Assert
WriteObjectInlineCall[] expectedWriteCalls = new WriteObjectInlineCall[]
{
new WriteObjectInlineCall { Graph = _customers[0], WriteContext = _writeContext },
new WriteObjectInlineCall { Graph = _customers[1], WriteContext = _writeContext }
};
AssertEqual(expectedWriteCalls, spy.WriteObjectInlineCalls);
mockWriter.Verify();
Assert.Equal(expectedNextLink, actualFeed.NextPageLink);
}
示例14: WriteObjectInline_Sets_NextPageLink_OnWriteEnd
public void WriteObjectInline_Sets_NextPageLink_OnWriteEnd()
{
// Arrange
Mock<ODataEntrySerializer> customerSerializer = new Mock<ODataEntrySerializer>(_customersType.ElementType(), ODataPayloadKind.Entry);
ODataSerializerProvider provider = ODataTestUtil.GetMockODataSerializerProvider(customerSerializer.Object);
var mockWriter = new Mock<ODataWriter>();
Uri expectedNextLink = new Uri("http://nextlink.com");
var result = new PageResult<Customer>(_customers, expectedNextLink, count: 0);
ODataFeed actualFeed = null;
mockWriter
.Setup(m => m.WriteStart(It.Is<ODataFeed>(feed => feed.NextPageLink == null)))
.Callback<ODataFeed>(feed => { actualFeed = feed; })
.Verifiable();
mockWriter
.Setup(m => m.WriteEnd())
.Callback(() =>
{
if (actualFeed != null)
{
Assert.Equal(expectedNextLink, actualFeed.NextPageLink);
}
})
.Verifiable();
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(result, mockWriter.Object, _writeContext);
// Assert
mockWriter.Verify();
}
示例15: 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);
}