public void CreateNamedPropertyExpression_WithMultipleProperty_ReturnsMemberAccessExpression(HandleNullPropagationOption options) { SelectExpandBinder binder = GetBinder <Customer>(_model, options); //Expression customer = Expression.Parameter(typeof(Customer)); output will be different. Expression customer = Expression.Constant(new Customer()); IEdmStructuralProperty homeLocationProperty = _customer.StructuralProperties().Single(c => c.Name == "HomeLocation"); IEdmStructuralProperty streetProperty = _address.StructuralProperties().Single(c => c.Name == "Street"); ODataSelectPath selectPath = new ODataSelectPath(new PropertySegment(homeLocationProperty), new PropertySegment(streetProperty)); PathSelectItem pathSelectItem = new PathSelectItem(selectPath); NamedPropertyExpression namedProperty = binder.CreateNamedPropertyExpression(customer, _customer, pathSelectItem); Assert.NotNull(namedProperty); /* * Assert.NotNull(namedProperty); * Assert.Equal("\"VipAddress\"", namedProperty.Name.ToString()); * * if (options != HandleNullPropagationOption.True) * { * Assert.Equal("(value(NS.Customer) As VipCustomer).VipAddress", namedProperty.Value.ToString()); * } * else * { * Assert.Equal("IIF(((value(NS.Customer) As VipCustomer) == null)," + * " null," + * " (value(NS.Customer) As VipCustomer).VipAddress)", namedProperty.Value.ToString()); * }*/ }
public void CreateNamedPropertyExpression_WithDerivedProperty_ReturnsMemberAccessExpression(HandleNullPropagationOption options) { SelectExpandBinder binder = GetBinder <Customer>(_model, options); //Expression customer = Expression.Parameter(typeof(Customer)); output will be different. Expression customer = Expression.Constant(new Customer()); IEdmStructuralProperty vipAddressProperty = _vipCustomer.StructuralProperties().Single(c => c.Name == "VipAddress"); ODataSelectPath selectPath = new ODataSelectPath(new TypeSegment(_vipCustomer, _customer, null), new PropertySegment(vipAddressProperty)); PathSelectItem pathSelectItem = new PathSelectItem(selectPath); NamedPropertyExpression namedProperty = binder.CreateNamedPropertyExpression(customer, _customer, pathSelectItem); Assert.NotNull(namedProperty); Assert.Equal("\"VipAddress\"", namedProperty.Name.ToString()); if (options != HandleNullPropagationOption.True) { Assert.Equal("(value(NS.Customer) As VipCustomer).VipAddress", namedProperty.Value.ToString()); } else { Assert.Equal("IIF(((value(NS.Customer) As VipCustomer) == null)," + " null," + " (value(NS.Customer) As VipCustomer).VipAddress)", namedProperty.Value.ToString()); } }
public void CreateNamedPropertyExpression_NonDerivedProperty_ReturnsMemberAccessExpression(HandleNullPropagationOption options) { SelectExpandBinder binder = GetBinder <Customer>(_model, options); Expression customer = Expression.Constant(new Customer()); IEdmStructuralProperty homeAddressProperty = _customer.StructuralProperties().Single(c => c.Name == "HomeLocation"); ODataSelectPath selectPath = new ODataSelectPath(new PropertySegment(homeAddressProperty)); PathSelectItem pathSelectItem = new PathSelectItem(selectPath); NamedPropertyExpression namedProperty = binder.CreateNamedPropertyExpression(customer, _customer, pathSelectItem); Assert.NotNull(namedProperty); Assert.Equal("\"HomeLocation\"", namedProperty.Name.ToString()); if (options != HandleNullPropagationOption.True) { Assert.Equal("value(NS.Customer).HomeLocation", namedProperty.Value.ToString()); } else { Assert.Equal("IIF((value(NS.Customer) == null)," + " null," + " value(NS.Customer).HomeLocation)", namedProperty.Value.ToString()); } }
public void CreateNamedPropertyExpression_WithMultiplePropertyAndType_ReturnsMemberAccessExpression(HandleNullPropagationOption options) { SelectExpandBinder binder = GetBinder <Customer>(_model, options); Expression customer = Expression.Parameter(typeof(Customer)); // output will be different. // Expression customer = Expression.Constant(new Customer()); SelectExpandClause selectExpandClause = ParseSelectExpand("HomeLocation/NS.CnAddress/Street", null); PathSelectItem pathSelectItem = selectExpandClause.SelectedItems.First() as PathSelectItem; NamedPropertyExpression namedProperty = binder.CreateNamedPropertyExpression(customer, _customer, pathSelectItem); Assert.NotNull(namedProperty); /* * Assert.NotNull(namedProperty); * Assert.Equal("\"VipAddress\"", namedProperty.Name.ToString()); * * if (options != HandleNullPropagationOption.True) * { * Assert.Equal("(value(NS.Customer) As VipCustomer).VipAddress", namedProperty.Value.ToString()); * } * else * { * Assert.Equal("IIF(((value(NS.Customer) As VipCustomer) == null)," + * " null," + * " (value(NS.Customer) As VipCustomer).VipAddress)", namedProperty.Value.ToString()); * }*/ }
public void CreatePropertyContainer_WithNullPropertyName_DoesntIncludeTheProperty() { // Arrange Expression propertyName = Expression.Constant(null, typeof(string)); Expression propertyValue = Expression.Constant(new TestEntity()); NamedPropertyExpression property = new NamedPropertyExpression(propertyName, propertyValue); var properties = new[] { property, property }; // Act Expression containerExpression = PropertyContainer.CreatePropertyContainer(properties); // Assert PropertyContainer container = ToContainer(containerExpression); Assert.Empty(container.ToDictionary(new IdentityPropertyMapper(), includeAutoSelected: true)); }
public void ToDictionary_Throws_IfMappingFunctionReturns_NullOrEmpty(string mappedName) { // Arrange IList <NamedPropertyExpression> properties = new NamedPropertyExpression[] { new NamedPropertyExpression(name: Expression.Constant("PropA"), value: Expression.Constant(3)) }; Expression containerExpression = PropertyContainer.CreatePropertyContainer(properties); PropertyContainer container = ToContainer(containerExpression); Mock <IPropertyMapper> mapperMock = new Mock <IPropertyMapper>(); mapperMock.Setup(m => m.MapProperty("PropA")).Returns(mappedName); // Act & Assert ExceptionAssert.Throws <InvalidOperationException>(() => container.ToDictionary(mapperMock.Object), "The key mapping for the property 'PropA' can't be null or empty."); }
public void ToDictionary_AppliesMappingToAllProperties() { // Arrange IList <NamedPropertyExpression> properties = new NamedPropertyExpression[] { new NamedPropertyExpression(name: Expression.Constant("PropA"), value: Expression.Constant(3)), new NamedPropertyExpression(name: Expression.Constant("PropB"), value: Expression.Constant(6)) }; Expression containerExpression = PropertyContainer.CreatePropertyContainer(properties); PropertyContainer container = ToContainer(containerExpression); Mock <IPropertyMapper> mapperMock = new Mock <IPropertyMapper>(); mapperMock.Setup(m => m.MapProperty("PropA")).Returns("PropertyA"); mapperMock.Setup(m => m.MapProperty("PropB")).Returns("PropB"); //Act IDictionary <string, object> result = container.ToDictionary(mapperMock.Object); //Assert Assert.NotNull(result); Assert.True(result.ContainsKey("PropertyA")); Assert.True(result.ContainsKey("PropB")); }