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

            Assert.Equal(1, properties.Length);
            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);
        }
Example #3
0
        public EntityTypeConfiguration <TEntityType> HasKey <TKey>(Expression <Func <TEntityType, TKey> > keyDefinitionExpression)
        {
            ICollection <PropertyInfo> properties = PropertySelectorVisitor.GetSelectedProperties(keyDefinitionExpression);

            foreach (PropertyInfo property in properties)
            {
                _configuration.HasKey(property);
            }
            return(this);
        }
        public void FailOnUnsupportedExpressionNodeType()
        {
            Expression <Func <AddressEntity, AddressEntity> > expr = (a) => CreateAddress(a.ID);
            var exception = Assert.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 = Assert.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 = Assert.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 = Assert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal(string.Format("Member '{0}.Field' is not a property.", typeof(WorkItem).FullName), exception.Message);
        }