emits SQL that deals with spaces when calculating lengths.
Inheritance: Remotion.Linq.Clauses.Expressions.ExtensionExpression
    public void Initialization_Char ()
    {
      var charExpression = Expression.Constant ('t');
      var lengthExpression = new SqlLengthExpression (charExpression);

      Assert.That (lengthExpression.Expression, Is.SameAs (charExpression));
      Assert.That (lengthExpression.Type, Is.EqualTo (typeof (int)));
    }
    public void Initialization_String ()
    {
      var stringExpression = Expression.Constant ("test");
      var lengthExpression = new SqlLengthExpression (stringExpression);

      Assert.That (lengthExpression.Expression, Is.SameAs (stringExpression));
      Assert.That (lengthExpression.Type, Is.EqualTo (typeof (int)));
    }
    public Expression Transform (MethodCallExpression methodCallExpression)
    {
      ArgumentUtility.CheckNotNull ("methodCallExpression", methodCallExpression);

      MethodCallTransformerUtility.CheckArgumentCount (methodCallExpression, 1);
      MethodCallTransformerUtility.CheckStaticMethod (methodCallExpression);

      var isNullExpression = new SqlIsNullExpression (methodCallExpression.Arguments[0]);
      var lenExpression = new SqlLengthExpression (methodCallExpression.Arguments[0]);
      var lenIsZeroExpression = Expression.Equal (lenExpression, new SqlLiteralExpression (0));

      return Expression.OrElse (isNullExpression, lenIsZeroExpression);
    }
    public void Transform ()
    {
      var method = typeof (string).GetMethod ("get_Length", new Type[] { });
      var objectExpression = Expression.Constant ("Test");
      var expression = Expression.Call (objectExpression, method);
      var transformer = new StringLengthMethodCallTransformer ();

      var result = transformer.Transform (expression);

      var expectedResult = new SqlLengthExpression (objectExpression);

      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }
    public void Transform ()
    {
      var method = typeof (string).GetMethod ("IsNullOrEmpty", new[] { typeof(string) });
      var objectExpression = Expression.Constant ("Test");
      var expression = Expression.Call (method, objectExpression);
      var transformer = new IsNullOrEmptyMethodCallTransformer ();

      var result = transformer.Transform (expression);

      var expectedIsNullExpression = new SqlIsNullExpression (objectExpression);
      var expectedLenExpression = new SqlLengthExpression (objectExpression);
      var expectedResult = Expression.OrElse (expectedIsNullExpression, Expression.Equal (expectedLenExpression, new SqlLiteralExpression(0)));
      
      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }
 public Expression VisitSqlLengthExpression (SqlLengthExpression expression)
 {
   return VisitChildrenWithGivenSemantics (expression, SqlExpressionContext.SingleValueRequired);
 }
    public void VisitSqlLengthExpression_Char ()
    {
      var innnerExpression = Expression.Constant ('t');
      var expression = new SqlLengthExpression (innnerExpression);

      SqlGeneratingExpressionVisitor.GenerateSql (expression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText (), Is.EqualTo ("(LEN((@1 + '#')) - 1)"));
      Assert.That (_commandBuilder.GetCommandParameters ()[0].Value, Is.EqualTo ('t'));
    }
    public Expression Transform (MethodCallExpression methodCallExpression)
    {
      MethodCallTransformerUtility.CheckArgumentCount (methodCallExpression, 1, 2, 3);
      MethodCallTransformerUtility.CheckInstanceMethod (methodCallExpression);

      if (methodCallExpression.Arguments.Count == 1)
      {
        var lenExpression = new SqlLengthExpression (methodCallExpression.Arguments[0]);
        var testPredicate = Expression.Equal (lenExpression, new SqlLiteralExpression (0));
        var charIndexExpression = new SqlFunctionExpression (
            methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], methodCallExpression.Object);
        var elseValue = Expression.Subtract (charIndexExpression, new SqlLiteralExpression (1));

        return Expression.Condition (testPredicate, new SqlLiteralExpression (0), elseValue);
      }
      else if (methodCallExpression.Arguments.Count == 2)
      {
        var startIndexExpression = Expression.Add (methodCallExpression.Arguments[1], new SqlLiteralExpression (1));

        var lenArgExpression = new SqlLengthExpression (methodCallExpression.Arguments[0]);
        var leftTestPredicate = Expression.Equal (lenArgExpression, new SqlLiteralExpression (0));

        var lenObjectExpression = new SqlLengthExpression (methodCallExpression.Object);
        var rightTestpredicate = Expression.LessThanOrEqual (startIndexExpression, lenObjectExpression);
        var testPredicate = Expression.AndAlso (leftTestPredicate, rightTestpredicate);

        var charIndexExpression = new SqlFunctionExpression (
            methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], methodCallExpression.Object, startIndexExpression);

        var elseValue = Expression.Subtract (charIndexExpression, new SqlLiteralExpression (1));

        return Expression.Condition (testPredicate, methodCallExpression.Arguments[1], elseValue);
      }
      else if (methodCallExpression.Arguments.Count == 3)
      {
        var startIndexExpression = Expression.Add (methodCallExpression.Arguments[1], new SqlLiteralExpression (1));

        var lenArgExpression = new SqlLengthExpression (methodCallExpression.Arguments[0]);
        var leftTestPredicate = Expression.Equal (lenArgExpression, new SqlLiteralExpression (0));

        var lenObjectExpression = new SqlLengthExpression (methodCallExpression.Object);
        var rightTestpredicate = Expression.LessThanOrEqual (startIndexExpression, lenObjectExpression);
        var testPredicate = Expression.AndAlso (leftTestPredicate, rightTestpredicate);

        var startAddCountExpression = Expression.Add (methodCallExpression.Arguments[1], methodCallExpression.Arguments[2]);
        var substringExpression = new SqlFunctionExpression (
            typeof (string), "SUBSTRING", methodCallExpression.Object, new SqlLiteralExpression (1), startAddCountExpression);

        var charIndexExpression = new SqlFunctionExpression (
            methodCallExpression.Type, "CHARINDEX", methodCallExpression.Arguments[0], substringExpression, startIndexExpression);

        var elseValue = Expression.Subtract (charIndexExpression, new SqlLiteralExpression (1));

        return Expression.Condition (testPredicate, methodCallExpression.Arguments[1], elseValue);
      }
      else
      {
        var message = string.Format (
            "IndexOf function with {0} arguments is not supported. Expression: '{1}'",
            methodCallExpression.Arguments.Count,
            FormattingExpressionTreeVisitor.Format (methodCallExpression));
        throw new NotSupportedException (message);
      }
    }
    public void VisitSqlLengthExpression ()
    {
      var expression = new SqlLengthExpression (Expression.Constant ("test"));

      var result = _predicateRequiredVisitor.VisitSqlLengthExpression (expression);

      Assert.That (result, Is.SameAs (expression));
    }
 public void SetUp ()
 {
   _innerExpression = Expression.Constant ("test");
   _lengthExpression = new SqlLengthExpression (_innerExpression);
 }