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);
        }
        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 Property_PageSize()
        {
            int pageSize = 42;
            TruncatedCollection <int> collection = new TruncatedCollection <int>(new[] { 1, 2, 3 }, pageSize);

            Assert.Equal(pageSize, collection.PageSize);
        }
        public void CtorTruncatedCollection_SetsProperties()
        {
            // Arrange & Act
            IEnumerable <int>         source     = new[] { 1, 2, 3, 5, 7 };
            TruncatedCollection <int> collection = new TruncatedCollection <int>(source, 3, 5);

            // Arrange
            Assert.Equal(3, collection.PageSize);
            Assert.Equal(5, collection.TotalCount);
            Assert.True(collection.IsTruncated);
            Assert.Equal(3, collection.Count);
            Assert.Equal(new[] { 1, 2, 3 }, collection);
        }
        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 GetEnumerator_DoesNotTruncate_IfPageSizeIsGreaterThanOrEqualToCollectionSize(int pageSize)
        {
            TruncatedCollection<int> collection = new TruncatedCollection<int>(new[] { 1, 2, 3 }, pageSize);

            Assert.Equal(new[] { 1, 2, 3 }, collection);
        }
        public void GetEnumerator_Truncates_IfPageSizeIsLessThanCollectionSize()
        {
            TruncatedCollection<int> collection = new TruncatedCollection<int>(new[] { 1, 2, 3 }, pageSize: 2);

            Assert.Equal(new[] { 1, 2 }, collection);
        }
 public void Property_PageSize()
 {
     int pageSize = 42;
     TruncatedCollection<int> collection = new TruncatedCollection<int>(new[] { 1, 2, 3 }, pageSize);
     Assert.Equal(pageSize, collection.PageSize);
 }
 public void Property_IsTruncated(int pageSize, bool expectedResult)
 {
     TruncatedCollection<int> collection = new TruncatedCollection<int>(new[] { 1, 2, 3 }, pageSize);
     Assert.Equal(expectedResult, collection.IsTruncated);
 }
Пример #10
0
        public void GetEnumerator_DoesNotTruncate_IfPageSizeIsGreaterThanOrEqualToCollectionSize(int pageSize)
        {
            TruncatedCollection <int> collection = new TruncatedCollection <int>(new[] { 1, 2, 3 }, pageSize);

            Assert.Equal(new[] { 1, 2, 3 }, collection);
        }
Пример #11
0
        public void GetEnumerator_Truncates_IfPageSizeIsLessThanCollectionSize()
        {
            TruncatedCollection <int> collection = new TruncatedCollection <int>(new[] { 1, 2, 3 }, pageSize: 2);

            Assert.Equal(new[] { 1, 2 }, collection);
        }
Пример #12
0
        public void Property_IsTruncated(int pageSize, bool expectedResult)
        {
            TruncatedCollection <int> collection = new TruncatedCollection <int>(new[] { 1, 2, 3 }, pageSize);

            Assert.Equal(expectedResult, collection.IsTruncated);
        }