Generates SQL text for BinaryExpression instances.
Beispiel #1
0
        protected SqlGeneratingExpressionVisitor(ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("stage", stage);

            _commandBuilder = commandBuilder;
            _binaryExpressionTextGenerator = new BinaryExpressionTextGenerator(commandBuilder, this);
            _stage = stage;
        }
    public void SetUp ()
    {
      _commandBuilder = new SqlCommandBuilder();

      _expressionVisitorMock = MockRepository.GenerateStrictMock<ExpressionTreeVisitor>();

      _leftIntegerExpression = Expression.Constant (1);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_leftIntegerExpression))
          .WhenCalled (mi => _commandBuilder.Append ("left"))
          .Return (_leftIntegerExpression);

      _rightIntegerExpression = Expression.Constant (2);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_rightIntegerExpression))
          .WhenCalled (mi => _commandBuilder.Append ("right"))
          .Return (_rightIntegerExpression);

      _leftDoubleExpression = Expression.Constant (1D);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_leftDoubleExpression))
          .WhenCalled (mi => _commandBuilder.Append ("leftDouble"))
          .Return (_leftDoubleExpression);

      _rightDoubleExpression = Expression.Constant (2D);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_rightDoubleExpression))
          .WhenCalled (mi => _commandBuilder.Append ("rightDouble"))
          .Return (_rightDoubleExpression);

      _leftStringExpression = Expression.Constant ("Left");
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_leftStringExpression))
          .WhenCalled (mi => _commandBuilder.Append ("leftString"))
          .Return (_leftStringExpression);

      _rightStringExpression = Expression.Constant ("Right");
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_rightStringExpression))
          .WhenCalled (mi => _commandBuilder.Append ("rightString"))
          .Return (_rightStringExpression);

      _nullExpression = Expression.Constant (null, typeof (string));
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_nullExpression))
          .WhenCalled (mi => _commandBuilder.Append ("NULL"))
          .Return (_rightStringExpression);

      _trueExpression = Expression.Constant (true);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_trueExpression))
          .WhenCalled (mi => _commandBuilder.Append ("true"))
          .Return (_trueExpression);

      _falseExpression = Expression.Constant (false);
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_falseExpression))
          .WhenCalled (mi => _commandBuilder.Append ("false"))
          .Return (_falseExpression);

      _nullableTrueExpression = Expression.Constant (true, typeof (bool?));
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_nullableTrueExpression))
          .WhenCalled (mi => _commandBuilder.Append ("true"))
          .Return (_nullableTrueExpression);

      _nullableFalseExpression = Expression.Constant (false, typeof (bool?));
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_nullableFalseExpression))
          .WhenCalled (mi => _commandBuilder.Append ("false"))
          .Return (_nullableFalseExpression);

      _sqlEntityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook));
      _expressionVisitorMock
          .Stub (stub => stub.VisitExpression (_sqlEntityExpression))
          .WhenCalled (mi => _commandBuilder.Append ("[c].[ID]"))
          .Return (((SqlEntityExpression) _sqlEntityExpression).GetIdentityExpression());

      _generator = new BinaryExpressionTextGenerator (_commandBuilder, _expressionVisitorMock);
    }