public void CanGetSingleSelectedProperty()
        {
            Expression <Func <AddressEntity, int> > expr = a => a.ID;
            var properties = PropertySelectorVisitor.GetSelectedProperties(expr).ToArray();

            Assert.Single(properties);
            Assert.Equal("ID", properties[0].Name);
        }
        public void CanGetMultipleSelectedProperties()
        {
            var expr       = Expr((AddressEntity a) => new { a.ID, a.ZipCode });
            var properties = PropertySelectorVisitor.GetSelectedProperties(expr).ToArray();

            Assert.Equal(2, properties.Length);
            Assert.Equal("ID", properties[0].Name);
            Assert.Equal("ZipCode", properties[1].Name);
        }
        public void FailOnUnsupportedExpressionNodeType()
        {
            Expression <Func <AddressEntity, AddressEntity> > expr = (a) => CreateAddress(a.ID);
            var exception = ExceptionAssert.Throws <NotSupportedException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("Unsupported Expression NodeType.", exception.Message);
        }
        public void FailWhenMemberExpressionNotBoundToParameter()
        {
            Expression <Func <AddressEntity, int> > expr = (a) => new AddressEntity().ID;
            var exception = ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("MemberExpressions must be bound to the LambdaExpression parameter.", exception.Message);
        }
        public void FailWhenLambdaExpressionHasMoreThanOneParameter()
        {
            Expression <Func <AddressEntity, AddressEntity, int> > expr = (a1, a2) => a1.ID;
            var exception = ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("The LambdaExpression must have exactly one parameter.", exception.Message);
        }
        public void FailWhenLambdaExpressionAccessesFields()
        {
            Expression <Func <WorkItem, int> > expr = w => w.Field;
            var exception = ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal(string.Format("Member '{0}.Field' is not a property.", typeof(WorkItem).FullName), exception.Message);
        }
 public static IEdmProperty GetProperty <T, TPropertyType>(this IEdmModel model,
                                                           Expression <Func <T, TPropertyType> > propertyExpression)
 {
     return(model.GetProperty(PropertySelectorVisitor.GetSelectedProperty(propertyExpression)));
 }