public void CreateResourceSet_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties()
        {
            // Arrange
            CustomersModelWithInheritance model              = new CustomersModelWithInheritance();
            IEdmCollectionTypeReference   customersType      = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference()));
            ODataResourceSetSerializer    serializer         = new ODataResourceSetSerializer(_serializerProvider);
            SelectExpandClause            selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true);
            IEdmNavigationProperty        ordersProperty     = model.Customer.NavigationProperties().First();
            ResourceContext entity = new ResourceContext
            {
                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
            ODataResourceSet resourceSet = serializer.CreateResourceSet(orders, _customersType, nestedContext);

            // Assert
            Assert.Equal("http://navigation-link/?$skip=1", resourceSet.NextPageLink.AbsoluteUri);
        }
        public void CreateResourceSet_Ignores_CountValue_ForInnerResourceSets()
        {
            // Arrange
            ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(_serializerProvider);
            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);
            ResourceContext        entity             = new ResourceContext
            {
                SerializerContext =
                    new ODataSerializerContext {
                    Request = request, NavigationSource = _customerSet, Model = _model
                }
            };
            ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, navProp);

            // Act
            ODataResourceSet resourceSet = serializer.CreateResourceSet(result, _customersType, nestedContext);

            // Assert
            Assert.Null(resourceSet.Count);
        }
        public void CreateResource_Sets_NextPageLinkForPageResult()
        {
            // Arrange
            ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(_serializerProvider);
            Uri        expectedNextLink           = new Uri("http://nextlink.com");
            const long ExpectedCountValue         = 1000;

            var result = new PageResult <Customer>(_customers, expectedNextLink, ExpectedCountValue);

            // Act
            ODataResourceSet resourceSet = serializer.CreateResourceSet(result, _customersType, new ODataSerializerContext());

            // Assert
            Assert.Equal(expectedNextLink, resourceSet.NextPageLink);
        }
        public void CreateODataFeed_Sets_DeltaLinkFromContext()
        {
            // Arrange
            ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(_serializerProvider);
            Uri expectedDeltaLink      = new Uri("http://deltalink.com");
            HttpRequestMessage request = new HttpRequestMessage();

            request.ODataProperties().DeltaLink = expectedDeltaLink;
            var result = new object[0];

            // Act
            ODataResourceSet feed = serializer.CreateResourceSet(result, _customersType, new ODataSerializerContext {
                Request = request
            });

            // Assert
            Assert.Equal(expectedDeltaLink, feed.DeltaLink);
        }
        public void CreateResourceSet_Sets_CountValueFromContext()
        {
            // Arrange
            ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(_serializerProvider);
            const long         ExpectedCountValue = 1000;
            HttpRequestMessage request            = new HttpRequestMessage();

            request.ODataProperties().TotalCount = ExpectedCountValue;
            var result = new object[0];

            // Act
            ODataResourceSet resourceSet = serializer.CreateResourceSet(result, _customersType, new ODataSerializerContext {
                Request = request
            });

            // Assert
            Assert.Equal(ExpectedCountValue, resourceSet.Count);
        }
        public void CreateResourceSet_SetsODataOperations()
        {
            // Arrange
            CustomersModelWithInheritance model         = new CustomersModelWithInheritance();
            IEdmCollectionTypeReference   customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference()));
            ODataResourceSetSerializer    serializer    = new ODataResourceSetSerializer(_serializerProvider);
            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
            ODataResourceSet resourceSet = serializer.CreateResourceSet(result, customersType, context);

            // Assert
            Assert.Equal(1, resourceSet.Actions.Count());
            Assert.Equal(2, resourceSet.Functions.Count());
        }