当前位置: 首页>>代码示例>>C#>>正文


C# ODataFeedSerializer.WriteObjectInline方法代码示例

本文整理汇总了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();
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:34,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:30,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:18,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFeedSerializerTests.cs

示例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.");
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:14,代码来源:ODataFeedSerializerTests.cs

示例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.");
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:11,代码来源:ODataFeedSerializerTests.cs

示例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'.");
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataFeedSerializerTests.cs

示例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'.");
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataFeedSerializerTests.cs

示例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");
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:7,代码来源:ODataFeedSerializerTests.cs

示例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);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFeedSerializerTests.cs

示例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);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:38,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFeedSerializerTests.cs

示例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);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:25,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:34,代码来源:ODataFeedSerializerTests.cs

示例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();
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:23,代码来源:ODataFeedSerializerTests.cs


注:本文中的System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。