public void CreateODataFeed_Ignores_CountValue_ForInnerFeeds() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().TotalCount = 42; var result = new object[0]; IEdmNavigationProperty navProp = _customerSet.EntityType().NavigationProperties().First(); SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true); EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = new ODataSerializerContext { Request = request, NavigationSource = _customerSet, Model = _model } }; ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, navProp); // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, nestedContext); // Assert Assert.Null(feed.Count); }
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); 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 { NavigationSource = 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); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(); linkBuilder.AddNavigationPropertyLinkBuilder(ordersProperty, new NavigationLinkBuilder((entityContext, navigationProperty) => new Uri("http://navigation-link/"), false)); model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder); model.Model.SetNavigationSourceLinkBuilder(model.Orders, new NavigationSourceLinkBuilderAnnotation()); // Act ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext); // Assert Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri); }
public void CreateODataFeed_Sets_NextPageLinkForPageResult() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); Uri expectedNextLink = new Uri("http://nextlink.com"); const long ExpectedCountValue = 1000; var result = new PageResult <Customer>(_customers, expectedNextLink, ExpectedCountValue); // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext()); // Assert Assert.Equal(expectedNextLink, feed.NextPageLink); }
public void CreateODataFeed_Sets_DeltaLinkFromContext() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); Uri expectedDeltaLink = new Uri("http://deltalink.com"); HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().DeltaLink = expectedDeltaLink; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request }); // Assert Assert.Equal(expectedDeltaLink, feed.DeltaLink); }
public void CreateODataFeed_Sets_CountValueFromContext() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); const long ExpectedCountValue = 1000; HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().TotalCount = ExpectedCountValue; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request }); // Assert Assert.Equal(ExpectedCountValue, feed.Count); }
public void CreateODataFeed_SetsODataOperations() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); ODataSerializerContext context = new ODataSerializerContext { NavigationSource = model.Customers, Request = new HttpRequestMessage(), Model = model.Model, MetadataLevel = ODataMetadataLevel.FullMetadata, Url = CreateMetadataLinkFactory("http://IgnoreMetadataPath") }; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, customersType, context); // Assert Assert.Equal(1, feed.Actions.Count()); Assert.Equal(2, feed.Functions.Count()); }
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); 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 { NavigationSource = 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<NavigationSourceLinkBuilderAnnotation> linkBuilder = new Mock<NavigationSourceLinkBuilderAnnotation>(); linkBuilder.Setup(l => l.BuildNavigationLink(entity, ordersProperty, ODataMetadataLevel.Default)).Returns(new Uri("http://navigation-link/")); model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder.Object); model.Model.SetNavigationSourceLinkBuilder(model.Orders, new NavigationSourceLinkBuilderAnnotation()); // Act ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext); // Assert Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri); }
public void CreateODataFeed_Ignores_CountValue_ForInnerFeeds() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().TotalCount = 42; var result = new object[0]; IEdmNavigationProperty navProp = _customerSet.EntityType().NavigationProperties().First(); SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true); EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = new ODataSerializerContext { Request = request, NavigationSource = _customerSet, Model = _model } }; ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, navProp); // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, nestedContext); // Assert Assert.Null(feed.Count); }
public void CreateODataFeed_Sets_FeedSelfLink() { // Arrange var feedInstance = new object[0]; ODataSerializerContext writeContext = new ODataSerializerContext { NavigationSource = _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/"); NavigationSourceLinkBuilderAnnotation linkBuilder = new MockNavigationSourceLinkBuilderAnnotation { 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.SetNavigationSourceLinkBuilder(_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); }
public void CreateODataFeed_Sets_NextPageLinkFromContext() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); Uri expectedNextLink = new Uri("http://nextlink.com"); HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().NextLink = expectedNextLink; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request }); // Assert Assert.Equal(expectedNextLink, feed.NextPageLink); }
public void CreateODataFeed_Sets_CountValueFromContext() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); const long ExpectedCountValue = 1000; HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().TotalCount = ExpectedCountValue; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext { Request = request }); // Assert Assert.Equal(ExpectedCountValue, feed.Count); }
public void CreateODataFeed_Sets_NextPageLinkForPageResult() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); Uri expectedNextLink = new Uri("http://nextlink.com"); const long ExpectedCountValue = 1000; var result = new PageResult<Customer>(_customers, expectedNextLink, ExpectedCountValue); // Act ODataFeed feed = serializer.CreateODataFeed(result, _customersType, new ODataSerializerContext()); // Assert Assert.Equal(expectedNextLink, feed.NextPageLink); }
public void CreateODataFeed_SetsODataOperations() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); ODataSerializerContext context = new ODataSerializerContext { NavigationSource = model.Customers, Request = new HttpRequestMessage(), Model = model.Model, MetadataLevel = ODataMetadataLevel.FullMetadata, Url = CreateMetadataLinkFactory("http://IgnoreMetadataPath") }; var result = new object[0]; // Act ODataFeed feed = serializer.CreateODataFeed(result, customersType, context); // Assert Assert.Equal(1, feed.Actions.Count()); Assert.Equal(2, feed.Functions.Count()); }
public void CreateODataFeed_Ignores_NextPageLink_ForInnerFeeds() { // Arrange ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); Uri nextLink = new Uri("http://somelink"); HttpRequestMessage request = new HttpRequestMessage(); request.ODataProperties().NextLink = nextLink; 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.NextPageLink); }