public void ApplyTo_Returns_Correct_Queryable_ForFilter(string filter, int[] customerIds) { // Arrange var model = new ODataModelBuilder() .Add_Order_EntityType() .Add_Customer_EntityType_With_Address() .Add_CustomerOrders_Relationship() .Add_Customer_EntityType_With_CollectionProperties() .Add_Customers_EntitySet() .GetEdmModel(); var context = new ODataQueryContext(model, typeof(Customer)); var queryOptionParser = new ODataQueryOptionParser( context.Model, context.ElementType, context.NavigationSource, new Dictionary<string, string> { { "$apply", string.Format("filter({0})", filter) } }); var filterOption = new ApplyQueryOption(string.Format("filter({0})", filter), context, queryOptionParser); IEnumerable<Customer> customers = CustomerApplyTestData; // Act IQueryable queryable = filterOption.ApplyTo(customers.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True }); // Assert Assert.NotNull(queryable); IEnumerable<Customer> actualCustomers = Assert.IsAssignableFrom<IEnumerable<Customer>>(queryable); Assert.Equal( customerIds, actualCustomers.Select(customer => customer.CustomerId)); }
public void ApplyTo_Returns_Correct_Queryable(string filter, List<Dictionary<string, object>> aggregation) { // Arrange var model = new ODataModelBuilder() .Add_Order_EntityType() .Add_Customer_EntityType_With_Address() .Add_CustomerOrders_Relationship() .Add_Customer_EntityType_With_CollectionProperties() .Add_Customers_EntitySet() .GetEdmModel(); var context = new ODataQueryContext(model, typeof(Customer)); var queryOptionParser = new ODataQueryOptionParser( context.Model, context.ElementType, context.NavigationSource, new Dictionary<string, string> { { "$apply", filter } }); var applyOption = new ApplyQueryOption(filter, context, queryOptionParser); IEnumerable<Customer> customers = CustomerApplyTestData; // Act IQueryable queryable = applyOption.ApplyTo(customers.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True }); // Assert Assert.NotNull(queryable); var actualCustomers = Assert.IsAssignableFrom<IEnumerable<DynamicTypeWrapper>>(queryable).ToList(); Assert.Equal(aggregation.Count(), actualCustomers.Count()); var aggEnum = actualCustomers.GetEnumerator(); foreach (var expected in aggregation) { aggEnum.MoveNext(); var agg = aggEnum.Current; foreach (var key in expected.Keys) { object value = GetValue(agg, key); Assert.Equal(expected[key], value); } } }