예제 #1
0
        public void ApplyToOfTSkipTokenQueryOption_Calls_ApplyToOfTOnSkipTokenHandler()
        {
            // Arrange
            Mock <SkipTokenHandler> handler   = new Mock <SkipTokenHandler>();
            ODataQuerySettings      settings  = new ODataQuerySettings();
            SkipTokenQueryValidator validator = new SkipTokenQueryValidator();
            IServiceProvider        sp        = new ServiceCollection()
                                                .AddSingleton <SkipTokenHandler>(handler.Object)
                                                .AddSingleton <SkipTokenQueryValidator>(validator)
                                                .BuildServiceProvider();

            ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int))
            {
                RequestContainer = sp
            };

            SkipTokenQueryOption skipTokenQuery = new SkipTokenQueryOption("abc", context);

            IQueryable <SkipTokenCustomer> query = Array.Empty <SkipTokenCustomer>().AsQueryable();

            handler.Setup(h => h.ApplyTo <SkipTokenCustomer>(query, skipTokenQuery, settings, null)).Returns(query).Verifiable();

            // Act
            skipTokenQuery.ApplyTo <SkipTokenCustomer>(query, settings, null);

            // Assert
            handler.Verify();
        }
예제 #2
0
        public void ApplyToOfTSkipTokenQueryOption_Applies_ToQuaryable()
        {
            // Arrange
            IEdmModel          model    = GetEdmModel();
            ODataQuerySettings settings = new ODataQuerySettings
            {
                HandleNullPropagation = HandleNullPropagationOption.False
            };
            ODataQueryContext    context        = new ODataQueryContext(model, typeof(SkipTokenCustomer));
            SkipTokenQueryOption skipTokenQuery = new SkipTokenQueryOption("Id-2", context);

            IQueryable <SkipTokenCustomer> customers = new List <SkipTokenCustomer>
            {
                new SkipTokenCustomer {
                    Id = 2, Name = "Aaron"
                },
                new SkipTokenCustomer {
                    Id = 1, Name = "Andy"
                },
                new SkipTokenCustomer {
                    Id = 3, Name = "Alex"
                }
            }.AsQueryable();

            // Act
            SkipTokenCustomer[] results = skipTokenQuery.ApplyTo(customers, settings, null).ToArray();

            // Assert
            SkipTokenCustomer skipTokenCustomer = Assert.Single(results);

            Assert.Equal(3, skipTokenCustomer.Id);
            Assert.Equal("Alex", skipTokenCustomer.Name);
        }
예제 #3
0
        public void ApplyToOfTSkipTokenQueryOption_Applies_ToQuaryable_WithOrderby()
        {
            // Arrange
            IEdmModel          model    = GetEdmModel();
            ODataQuerySettings settings = new ODataQuerySettings
            {
                HandleNullPropagation = HandleNullPropagationOption.False
            };
            ODataQueryContext context = new ODataQueryContext(model, typeof(SkipTokenCustomer));

            HttpRequest request = RequestFactory.Create(HttpMethods.Get, "http://server/Customers/?$orderby=Name&$skiptoken=Name-'Alex',Id-3");

            ODataQueryOptions    queryOptions   = new ODataQueryOptions(context, request);
            SkipTokenQueryOption skipTokenQuery = queryOptions.SkipToken;

            IQueryable <SkipTokenCustomer> customers = new List <SkipTokenCustomer>
            {
                new SkipTokenCustomer {
                    Id = 2, Name = "Caron"
                },
                new SkipTokenCustomer {
                    Id = 1, Name = "Bndy"
                },
                new SkipTokenCustomer {
                    Id = 3, Name = "Alex"
                },
                new SkipTokenCustomer {
                    Id = 4, Name = "Aab"
                }
            }.AsQueryable();

            // Act
            SkipTokenCustomer[] results = skipTokenQuery.ApplyTo(customers, settings, queryOptions).ToArray();

            // Assert
            Assert.Equal(2, results.Length);
            Assert.Equal(2, results[0].Id);
            Assert.Equal(1, results[1].Id);
        }