• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Serialization.ODataFeedSerializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer的典型用法代码示例。如果您正苦于以下问题:C# ODataFeedSerializer类的具体用法?C# ODataFeedSerializer怎么用?C# ODataFeedSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ODataFeedSerializer类属于System.Web.Http.OData.Formatter.Serialization命名空间,在下文中一共展示了ODataFeedSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
 }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:10,代码来源:DefaultODataSerializerProvider.cs


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


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


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


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


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


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


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


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


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


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


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


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


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


示例17: 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


示例18: Ctor_SetsProperty_EntityType

 public void Ctor_SetsProperty_EntityType()
 {
     ODataFeedSerializer serializer = new ODataFeedSerializer(_customersType, new DefaultODataSerializerProvider());
     Assert.Equal(_customersType.ElementType(), serializer.EntityType);
 }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:5,代码来源:ODataFeedSerializerTests.cs


示例19: WriteObjectInline_ThrowsArgumentNull_Writer

 public void WriteObjectInline_ThrowsArgumentNull_Writer()
 {
     ODataFeedSerializer serializer = new ODataFeedSerializer(_customersType, new DefaultODataSerializerProvider());
     Assert.ThrowsArgumentNull(
         () => serializer.WriteObjectInline(graph: null, writer: null, writeContext: new ODataSerializerContext()),
         "writer");
 }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:7,代码来源:ODataFeedSerializerTests.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.ODataSerializerContext类代码示例发布时间:2022-05-26
下一篇:
C# Serialization.DefaultODataSerializerProvider类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap