public void CanApplySkipOrderby() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var context = new ODataQueryContext(model, typeof(Customer)); var orderbyOption = new OrderByQueryOption("Name", context); var skipOption = new SkipQueryOption("1", context); var customers = (new List <Customer> { new Customer { CustomerId = 1, Name = "Andy" }, new Customer { CustomerId = 2, Name = "Aaron" }, new Customer { CustomerId = 3, Name = "Alex" } }).AsQueryable(); IQueryable queryable = orderbyOption.ApplyTo(customers); queryable = skipOption.ApplyTo(queryable, new ODataQuerySettings()); var results = ((IQueryable <Customer>)queryable).ToArray(); Assert.Equal(2, results.Length); Assert.Equal(3, results[0].CustomerId); Assert.Equal(1, results[1].CustomerId); }
public void ApplyInValidSkipQueryThrows(string skipValue) { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel(); var context = new ODataQueryContext(model, typeof(Customer)); var skip = new SkipQueryOption(skipValue, context); Assert.Throws <ODataException>(() => skip.ApplyTo(ODataQueryOptionTest.Customers, new ODataQuerySettings())); }
public void ApplyTo_WithUnTypedContext_Throws_InvalidOperation() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer); SkipQueryOption skip = new SkipQueryOption("42", context); IQueryable queryable = new Mock <IQueryable>().Object; // Act & Assert Assert.Throws <NotSupportedException>(() => skip.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."); }
public void CanApplySkip() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var skipOption = new SkipQueryOption("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 = skipOption.ApplyTo(customers).ToArray(); Assert.Equal(2, results.Length); Assert.Equal(2, results[0].CustomerId); Assert.Equal(3, results[1].CustomerId); }