public SelectExpandBinderTest() { _settings = new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.False }; _model = new CustomersModelWithInheritance(); _model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.Customer, new ClrTypeAnnotation(typeof(Customer))); _model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.SpecialCustomer, new ClrTypeAnnotation(typeof(SpecialCustomer))); _context = new ODataQueryContext(_model.Model, typeof(Customer)); _binder = new SelectExpandBinder(_settings, new DefaultAssembliesResolver(), new SelectExpandQueryOption("*", "", _context)); Customer customer = new Customer(); Order order = new Order { Customer = customer }; customer.Orders.Add(order); _queryable = new[] { customer }.AsQueryable(); }
public ODataCollectionSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _edmIntType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false); _customer = new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, }; ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider(); _collectionType = new EdmCollectionTypeReference(new EdmCollectionType(_edmIntType)); _serializer = new ODataCollectionSerializer(serializerProvider); }
public void ProjectAsWrapper_ProjectedValueContainsConcurrencyProperties_EvenIfNotPresentInSelectClause(string select) { // Arrange Customer customer = new Customer { ID = 42, City = "any" }; ODataQueryOptionParser parser = new ODataQueryOptionParser(_model.Model, _model.Customer, _model.Customers, new Dictionary<string, string> { { "$select", select } }); SelectExpandClause selectExpand = parser.ParseSelectAndExpand(); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Equal(customer.City, customerWrapper.Container.ToDictionary(new IdentityPropertyMapper())["City"]); }
public void ProjectAsWrapper_Element_ProjectedValueContains_SelectedStructuralProperties() { // Arrange Customer customer = new Customer { Name = "OData" }; ODataQueryOptionParser parser = new ODataQueryOptionParser(_model.Model, _model.Customer, _model.Customers, new Dictionary<string, string> { { "$select", "Name,Orders" }, { "$expand", "Orders" } }); SelectExpandClause selectExpand = parser.ParseSelectAndExpand(); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Equal(customer.Name, customerWrapper.Container.ToDictionary(new IdentityPropertyMapper())["Name"]); }
public void ProjectAsWrapper_Element_ProjectedValueDoesNotContainInstance_IfSelectionIsPartial() { // Arrange Customer customer = new Customer(); ODataQueryOptionParser parser = new ODataQueryOptionParser(_model.Model, _model.Customer, _model.Customers, new Dictionary<string, string> { { "$select", "ID,Orders" }, { "$expand", "Orders" } }); SelectExpandClause selectExpand = parser.ParseSelectAndExpand(); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert Assert.Equal(ExpressionType.MemberInit, projection.NodeType); Assert.Empty((projection as MemberInitExpression).Bindings.Where(p => p.Member.Name == "Instance")); SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Null(customerWrapper.Instance); }
public void ProjectAsWrapper_Element_ProjectedValueContainsModelID() { // Arrange Customer customer = new Customer(); SelectExpandClause selectExpand = new SelectExpandClause(new SelectItem[0], allSelected: true); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.NotNull(customerWrapper.ModelID); Assert.Same(_model.Model, ModelContainer.GetModel(customerWrapper.ModelID)); }
public void ProjectAsWrapper_Element_ProjectedValueContains_KeyPropertiesEvenIfNotPresentInSelectClause(string select) { // Arrange Customer customer = new Customer { ID = 42, FirstName = "OData" }; SelectExpandClause selectExpand = new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand(select, null, _model.Customer, _model.Customers); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Equal(customer.ID, customerWrapper.Container.ToDictionary(new IdentityPropertyMapper())["ID"]); }
public void ProjectAsWrapper_Element_ProjectedValueContains_SelectedStructuralProperties() { // Arrange Customer customer = new Customer { Name = "OData" }; SelectExpandClause selectExpand = new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand("Name,Orders", "Orders", _model.Customer, _model.Customers); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Equal(customer.Name, customerWrapper.Container.ToDictionary(new IdentityPropertyMapper())["Name"]); }
public void ProjectAsWrapper_Element_ProjectedValueContainsInstance_IfSelectionIsAll(string select) { // Arrange Customer customer = new Customer(); SelectExpandClause selectExpand = new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand(select, "Orders", _model.Customer, _model.Customers); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert Assert.Equal(ExpressionType.MemberInit, projection.NodeType); Assert.NotEmpty((projection as MemberInitExpression).Bindings.Where(p => p.Member.Name == "Instance")); SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Same(customer, customerWrapper.Instance); }
public void Post(Customer customer) { // NOOP }
public void ProjectAsWrapper_ProjectedValueContainsConcurrencyProperties_EvenIfNotPresentInSelectClause(string select) { // Arrange Customer customer = new Customer { ID = 42, City = "any" }; SelectExpandClause selectExpand = new ODataUriParser(_model.Model, serviceRoot: null).ParseSelectAndExpand(select, null, _model.Customer, _model.Customers); Expression source = Expression.Constant(customer); // Act Expression projection = _binder.ProjectAsWrapper(source, selectExpand, _model.Customer); // Assert SelectExpandWrapper<Customer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<Customer>; Assert.Equal(customer.City, customerWrapper.Container.ToDictionary()["City"]); }