Ejemplo n.º 1
0
        public void VisitConditionalExpression_WithType_AndChanges()
        {
            var test       = Expression.Constant(true);
            var ifTrue     = Expression.Constant(null, typeof(object));
            var ifFalse    = Expression.Constant("false", typeof(string));
            var expression = Expression.Condition(test, ifTrue, ifFalse, typeof(object));

            Expression newIfFalse = Expression.Constant("FALSE", typeof(string));

            VisitorMock.Expect(mock => mock.VisitExpression(expression.Test)).Return(expression.Test);
            VisitorMock.Expect(mock => mock.VisitExpression(expression.IfTrue)).Return(expression.IfTrue);
            VisitorMock.Expect(mock => mock.VisitExpression(expression.IfFalse)).Return(newIfFalse);

            var result = (ConditionalExpression)InvokeAndCheckVisitExpression("VisitConditionalExpression", expression);

            Assert.That(result, Is.Not.SameAs(expression));
            Assert.That(result.NodeType, Is.EqualTo(ExpressionType.Conditional));
            Assert.That(result.Type, Is.SameAs(typeof(object)));
            Assert.That(result.Test, Is.SameAs(expression.Test));
            Assert.That(result.IfTrue, Is.SameAs(ifTrue));
            Assert.That(result.IfFalse, Is.SameAs(newIfFalse));
        }