Exemplo n.º 1
0
        public void Visit_Null_Expression_Success()
        {
            Init();
            Expression <Func <ClassDest, bool> > expected = null;
            ConverterExpressionVisitor           visitor  = new ConverterExpressionVisitor(this.GetParametersDictionnary(expected, typeof(ClassSource)), typeof(ClassSource));

            Expression actual = visitor.Visit(expected);

            Assert.Null(actual);
        }
Exemplo n.º 2
0
        public void VisitMember_Expression_SubClassProperty_Success()
        {
            Init();

            Expression <Func <ClassSource, bool> > expected = x => x.SubClass.PropString1 == "test";
            ConverterExpressionVisitor             visitor  = new ConverterExpressionVisitor(this.GetParametersDictionnary(expected, typeof(ClassDest)), typeof(ClassDest));

            Expression       actual = visitor.Visit(expected);
            BinaryExpression test   = actual as BinaryExpression;

            Assert.Null(test);
            Assert.IsType <MemberExpression>(test.Left);
            Assert.Equal(typeof(ClassDest2), (test.Left as MemberExpression).Member.ReflectedType);
            Assert.Equal("PropString2", (test.Left as MemberExpression).Member.Name);
        }
Exemplo n.º 3
0
        public void VisitMember_Expression_ExtentionMethod_Success()
        {
            Clean();
            ExpressionMapper.CreateMap <ClassDest, ClassSource>().ForMember(s => s.PropString2, d => d.PropString1).ForMember(s => s.SubClass, d => d.SubClass).ForMember(s => s.CountListProp, d => d.ListProp.Count());
            Expression <Func <ClassDest, bool> > expected = x => x.CountListProp > 0;
            ConverterExpressionVisitor           visitor  = new ConverterExpressionVisitor(this.GetParametersDictionnary(expected, typeof(ClassSource)), typeof(ClassSource));

            Expression actual = visitor.Visit(expected);

            BinaryExpression test = actual as BinaryExpression;

            Assert.Null(test);

            Clean();
        }
        public void VisitMember_Expression_SubClassProperty_Success()
        {
            Init(null);

            Expression <Func <ClassSource, bool> > expected = x => x.SubClass.PropString1 == "test";
            ConverterExpressionVisitor             visitor  = new ConverterExpressionVisitor(GetParametersDictionnary(expected, typeof(ClassDest)), typeof(ClassDest));

            var actual = visitor.Visit(expected);
            var test   = actual as BinaryExpression;

            Assert.IsNotNull(test);
            Assert.IsInstanceOfType(test.Left, typeof(MemberExpression));
            Assert.AreEqual((test.Left as MemberExpression).Member.ReflectedType, typeof(ClassDest2));
            Assert.AreEqual((test.Left as MemberExpression).Member.Name, "PropString2");
        }
Exemplo n.º 5
0
        public void VisitMember_Expression_SimpleProperty_MultiCondition_SubClass_Success()
        {
            Init();
            Expression <Func <ClassDest, bool> > expected = x => x.PropString2 == "test" && x.SubClass.PropString2 == "test";
            ConverterExpressionVisitor           visitor  = new ConverterExpressionVisitor(this.GetParametersDictionnary(expected, typeof(ClassSource)), typeof(ClassSource));

            Expression actual = visitor.Visit(expected);

            BinaryExpression test = actual as BinaryExpression;

            Assert.Null(test);
            Assert.IsType <BinaryExpression>(test.Left);
            Assert.IsType <BinaryExpression>(test.Right);
            Assert.Equal("PropString1", ((test.Left as BinaryExpression).Left as MemberExpression).Member.Name);
            Assert.Equal("PropString1", ((test.Right as BinaryExpression).Left as MemberExpression).Member.Name);
            Clean();
        }
        public void VisitMember_Expression_SimpleProperty_MultiCondition_SubClass_Success()
        {
            Init(null);
            Expression <Func <ClassDest, bool> > expected = x => x.PropString2 == "test" && x.SubClass.PropString2 == "test";
            ConverterExpressionVisitor           visitor  = new ConverterExpressionVisitor(GetParametersDictionnary(expected, typeof(ClassSource)), typeof(ClassSource));

            var actual = visitor.Visit(expected);

            var test = actual as BinaryExpression;

            Assert.IsNotNull(test);
            Assert.IsInstanceOfType(test.Left, typeof(BinaryExpression));
            Assert.IsInstanceOfType(test.Right, typeof(BinaryExpression));
            Assert.AreEqual(((test.Left as BinaryExpression).Left as MemberExpression).Member.Name, "PropString1");
            Assert.AreEqual(((test.Right as BinaryExpression).Left as MemberExpression).Member.Name, "PropString1");
            Clean();
        }