本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline方法的典型用法代码示例。如果您正苦于以下问题:C# ODataFeedSerializer.WriteObjectInline方法的具体用法?C# ODataFeedSerializer.WriteObjectInline怎么用?C# ODataFeedSerializer.WriteObjectInline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer
的用法示例。
在下文中一共展示了ODataFeedSerializer.WriteObjectInline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: WriteObjectInline_Throws_TypeCannotBeSerialized_IfFeedContainsEntityThatCannotBeSerialized
public void WriteObjectInline_Throws_TypeCannotBeSerialized_IfFeedContainsEntityThatCannotBeSerialized()
{
// Arrange
Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>();
HttpRequestMessage request = new HttpRequestMessage();
serializerProvider.Setup(s => s.GetODataPayloadSerializer(_model, typeof(int), request)).Returns<ODataSerializer>(null);
IEnumerable instance = new object[] { 42 };
ODataFeedSerializer serializer = new ODataFeedSerializer(serializerProvider.Object);
// Act
Assert.Throws<SerializationException>(
() => serializer.WriteObjectInline(instance, _customersType, new Mock<ODataWriter>().Object, _writeContext),
"'Default.Customer' cannot be serialized using the ODataMediaTypeFormatter.");
}
示例6: WriteObjectInline_Throws_NullElementInCollection_IfFeedContainsNullElement
public void WriteObjectInline_Throws_NullElementInCollection_IfFeedContainsNullElement()
{
// Arrange
IEnumerable instance = new object[] { null };
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
// Act
Assert.Throws<SerializationException>(
() => serializer.WriteObjectInline(instance, _customersType, new Mock<ODataWriter>().Object, _writeContext),
"Collections cannot contain null elements.");
}
示例7: WriteObjectInline_ThrowsSerializationException_IfGraphIsNotEnumerable
public void WriteObjectInline_ThrowsSerializationException_IfGraphIsNotEnumerable()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.Throws<SerializationException>(
() => serializer.WriteObjectInline(graph: 42, expectedType: _customersType,
writer: new Mock<ODataWriter>().Object, writeContext: _writeContext),
"ODataFeedSerializer cannot write an object of type 'System.Int32'.");
}
示例8: WriteObjectInline_ThrowsSerializationException_CannotSerializerNull
public void WriteObjectInline_ThrowsSerializationException_CannotSerializerNull()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.Throws<SerializationException>(
() => serializer.WriteObjectInline(graph: null, expectedType: _customersType,
writer: new Mock<ODataWriter>().Object, writeContext: _writeContext),
"Cannot serialize a null 'feed'.");
}
示例9: WriteObjectInline_ThrowsArgumentNull_WriteContext
public void WriteObjectInline_ThrowsArgumentNull_WriteContext()
{
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
Assert.ThrowsArgumentNull(
() => serializer.WriteObjectInline(graph: null, expectedType: null, writer: new Mock<ODataWriter>().Object, writeContext: null),
"writeContext");
}
示例10: WriteObjectInline_Writes_RequestNextPageLink
public void WriteObjectInline_Writes_RequestNextPageLink()
{
// Arrange
var mockSerializerProvider = new Mock<ODataSerializerProvider>(_model);
var mockCustomerSerializer = new Mock<ODataSerializer>(ODataPayloadKind.Entry);
var mockWriter = new Mock<ODataWriter>();
Uri expectedNextLink = new Uri("http://nextlink.com");
_writeContext.Request = new HttpRequestMessage();
_writeContext.Request.Properties.Add("MS_NextPageLink", expectedNextLink);
mockSerializerProvider
.Setup(p => p.GetODataPayloadSerializer(typeof(Customer)))
.Returns(mockCustomerSerializer.Object);
mockWriter
.Setup(m => m.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
Assert.Equal(expectedNextLink, feed.NextPageLink);
});
_serializer = new ODataFeedSerializer(_customersType, mockSerializerProvider.Object);
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
}
示例11: 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);
}
示例12: WriteObjectInline_Writes_RequestCount
public void WriteObjectInline_Writes_RequestCount()
{
// Arrange
ODataSerializer customerSerializer = new StubODataSerializer(ODataPayloadKind.Entry);
ODataSerializerProvider provider = new FakeODataSerializerProvider(customerSerializer);
var mockWriter = new Mock<ODataWriter>();
long expectedCount = 12345;
_writeContext.InlineCount = expectedCount;
mockWriter
.Setup(m => m.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
Assert.Equal(expectedCount, feed.Count);
});
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
// Assert
mockWriter.Verify();
}
示例13: WriteObjectInline_Writes_RequestNextPageLink
public void WriteObjectInline_Writes_RequestNextPageLink()
{
// Arrange
ODataSerializer customerSerializer = new StubODataSerializer(ODataPayloadKind.Entry);
ODataSerializerProvider provider = new FakeODataSerializerProvider(customerSerializer);
var mockWriter = new Mock<ODataWriter>();
Uri expectedNextLink = new Uri("http://nextlink.com");
_writeContext.NextPageLink = expectedNextLink;
ODataFeed actualFeed = null;
mockWriter
.Setup(m => m.WriteStart(It.IsAny<ODataFeed>()))
.Callback((ODataFeed feed) =>
{
actualFeed = feed;
});
_serializer = new ODataFeedSerializer(_customersType, provider);
// Act
_serializer.WriteObjectInline(_customers, mockWriter.Object, _writeContext);
// Assert
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: 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();
}