示例#1
0
        public void ApplyInvalidSkipQueryThrows(string topValue)
        {
            var model   = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer), "Customers");
            var top     = new TopQueryOption(topValue, context);

            Assert.Throws <ODataException>(() =>
                                           top.ApplyTo(ODataQueryOptionTest.Customers));
        }
示例#2
0
        public void ApplyTo_WithUnTypedContext_Throws_InvalidOperation()
        {
            // Arrange
            CustomersModelWithInheritance model   = new CustomersModelWithInheritance();
            ODataQueryContext             context = new ODataQueryContext(model.Model, model.Customer);
            TopQueryOption top       = new TopQueryOption("42", context);
            IQueryable     queryable = new Mock <IQueryable>().Object;

            // Act & Assert
            Assert.Throws <NotSupportedException>(() => top.ApplyTo(queryable, new ODataQuerySettings()),
                                                  "The query option is not bound to any CLR type. 'ApplyTo' is only supported with a query option bound to a CLR type.");
        }
示例#3
0
        public void CanApplyTop()
        {
            var model     = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel();
            var topOption = new TopQueryOption("1", new ODataQueryContext(model, typeof(Customer), "Customers"));

            var customers = (new List <Customer> {
                new Customer {
                    CustomerId = 1, Name = "Andy"
                },
                new Customer {
                    CustomerId = 2, Name = "Aaron"
                },
                new Customer {
                    CustomerId = 3, Name = "Alex"
                }
            }).AsQueryable();

            var results = topOption.ApplyTo(customers).ToArray();

            Assert.Equal(1, results.Length);
            Assert.Equal(1, results[0].CustomerId);
        }
示例#4
0
        public void CanApplySkipTopOrderby()
        {
            var model         = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel();
            var context       = new ODataQueryContext(model, typeof(Customer), "Customers");
            var orderbyOption = new OrderByQueryOption("Name", context);
            var skipOption    = new SkipQueryOption("2", context);
            var topOption     = new TopQueryOption("2", context);

            var customers = (new List <Customer> {
                new Customer {
                    CustomerId = 1, Name = "Andy"
                },
                new Customer {
                    CustomerId = 2, Name = "Aaron"
                },
                new Customer {
                    CustomerId = 3, Name = "Alex"
                },
                new Customer {
                    CustomerId = 4, Name = "Ace"
                },
                new Customer {
                    CustomerId = 5, Name = "Abner"
                }
            }).AsQueryable();

            IQueryable queryable = orderbyOption.ApplyTo(customers);

            queryable = skipOption.ApplyTo(queryable);
            queryable = topOption.ApplyTo(queryable);
            var results = ((IQueryable <Customer>)queryable).ToArray();

            Assert.Equal(2, results.Length);
            Assert.Equal(4, results[0].CustomerId);
            Assert.Equal(3, results[1].CustomerId);
        }