Represents 'is null' in a comparison.
Inheritance: Remotion.Linq.Clauses.Expressions.ExtensionExpression
    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 ("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 SplitPotentialCompoundComparison (SqlIsNullExpression potentialCompoundComparison)
    {
      ArgumentUtility.CheckNotNull ("potentialCompoundComparison", potentialCompoundComparison);

      var innerExpressionAsNewExpression = potentialCompoundComparison.Expression as NewExpression;
      if (innerExpressionAsNewExpression != null)
      {
        if (innerExpressionAsNewExpression.Arguments.Count == 0)
          return Expression.Constant (false);

        return innerExpressionAsNewExpression.Arguments
            .Select (arg => (Expression) new SqlIsNullExpression (arg))
            .Aggregate (Expression.AndAlso);
      }

      return potentialCompoundComparison;
    }
    public void SplitPotentialCompoundComparison_SqlIsNullExpression_ExpandsNewExpression_ByCheckingAllArguments_ZeroArguments ()
    {
      var newExpression = Expression.New (TypeForNewExpression.GetConstructor());
      var sqlIsNullExpression = new SqlIsNullExpression (newExpression);

      var result = _compoundExpressionComparisonSplitter.SplitPotentialCompoundComparison (sqlIsNullExpression);

      var expected = Expression.Constant (false);
      SqlExpressionTreeComparer.CheckAreEqualTrees (expected, result);
    }
    public void SplitPotentialCompoundComparison_SqlIsNullExpression_ExpandsNewExpression_ByCheckingAllArguments_OnlyOneArgument ()
    {
      var arg1 = Expression.Constant (1);
      var newExpression = Expression.New (TypeForNewExpression.GetConstructor (typeof (int)), new[] { arg1 });
      var sqlIsNullExpression = new SqlIsNullExpression (newExpression);

      var result = _compoundExpressionComparisonSplitter.SplitPotentialCompoundComparison (sqlIsNullExpression);

      var expected = new SqlIsNullExpression (arg1);
      SqlExpressionTreeComparer.CheckAreEqualTrees (expected, result);
    }
    public void SplitPotentialCompoundComparison_SqlIsNullExpression_ReturnsNonNewExpression_Unchanged ()
    {
      var expression = Expression.Constant (1);
      var sqlIsNullExpression = new SqlIsNullExpression (expression);

      var result = _compoundExpressionComparisonSplitter.SplitPotentialCompoundComparison (sqlIsNullExpression);

      Assert.That (result, Is.SameAs (sqlIsNullExpression));
    }
    public Expression VisitSqlIsNullExpression (SqlIsNullExpression expression)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);

      var newExpression = ApplySingleValueContext (expression.Expression);
      if (newExpression != expression.Expression)
        return new SqlIsNullExpression (newExpression);
      return expression;
    }
    public void VisitSqlIsNullExpression_RevisitingTerminatesAfterInnerChanges_WithoutOuterChanges  ()
    {
      var inner = Expression.Constant (0);
      var isNullExpression = new SqlIsNullExpression (inner);

      var fakeResolvedInner = new SqlLiteralExpression (1);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (inner)).Return (fakeResolvedInner);

      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntityComparison (Arg<SqlIsNullExpression>.Is.Anything))
          .Return (null)
          .WhenCalled (mi => mi.ReturnValue = mi.Arguments[0]);
      _compoundComparisonSplitterMock
          .Expect (mock => mock.SplitPotentialCompoundComparison (Arg<SqlIsNullExpression>.Is.Anything))
          .Return (null)
          .WhenCalled (mi => mi.ReturnValue = mi.Arguments[0]);

      // No revisiting

      var result = _visitor.VisitExpression (isNullExpression);

      _resolverMock.VerifyAllExpectations ();
      _entityIdentityResolverMock.VerifyAllExpectations ();
      _compoundComparisonSplitterMock.VerifyAllExpectations ();

      Assert.That (result, Is.TypeOf<SqlIsNullExpression> ());
      Assert.That (((SqlIsNullExpression) result).Expression, Is.SameAs (fakeResolvedInner));
    }
    public void VisitSqlIsNullExpression ()
    {
      var inner = Expression.Constant (0);
      var isNullExpression = new SqlIsNullExpression (inner);

      var fakeResolvedInner = new SqlLiteralExpression (1);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (inner)).Return (fakeResolvedInner);

      var fakeResolvedEntityComparison = new SqlIsNullExpression (Expression.Constant (2));
      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntityComparison (Arg<SqlIsNullExpression>.Matches (e => e.Expression == fakeResolvedInner)))
          .Return (fakeResolvedEntityComparison);

      var fakeSplitCompoundComparison = new SqlIsNullExpression (Expression.Constant (3));
      _compoundComparisonSplitterMock
          .Expect (mock => mock.SplitPotentialCompoundComparison (fakeResolvedEntityComparison))
          .Return (fakeSplitCompoundComparison);

      // Result is revisited
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeSplitCompoundComparison.Expression))
          .Return (fakeSplitCompoundComparison.Expression);
      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntityComparison (fakeSplitCompoundComparison))
          .Return (fakeSplitCompoundComparison);
      _compoundComparisonSplitterMock
          .Expect (mock => mock.SplitPotentialCompoundComparison (fakeSplitCompoundComparison))
          .Return (fakeSplitCompoundComparison);
     
      var result = _visitor.VisitExpression (isNullExpression);

      _resolverMock.VerifyAllExpectations ();
      _entityIdentityResolverMock.VerifyAllExpectations ();
      _compoundComparisonSplitterMock.VerifyAllExpectations ();

      Assert.That (result, Is.SameAs (fakeSplitCompoundComparison));
    }
    public void VisitSqlIsNullExpression_AppliesSingleValueSemantics_ThrowsForComplexValue ()
    {
      var entityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook));
      var sqlIsNullExpressionWithEntity = new SqlIsNullExpression (entityExpression);

      Assert.That (() => _valueRequiredVisitor.VisitSqlIsNullExpression (sqlIsNullExpressionWithEntity), Throws.TypeOf<NotSupportedException> ());
    }
    public void ResolvePotentialEntityComparison_SqlIsNullExpression_ResolvesEntitiesToIdentity ()
    {
      var sqlIsNullExpression = new SqlIsNullExpression (_entityExpression);

      var result = _entityIdentityResolver.ResolvePotentialEntityComparison (sqlIsNullExpression);

      var expected = new SqlIsNullExpression (_entityExpression.GetIdentityExpression ());
      SqlExpressionTreeComparer.CheckAreEqualTrees (expected, result);
    }
    public void VisitSqlIsNullExpression ()
    {
      var expression = Expression.Constant ("test");
      var sqlIsNullExpression = new SqlIsNullExpression (expression);

      SqlGeneratingExpressionVisitor.GenerateSql (
          sqlIsNullExpression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText(), Is.EqualTo ("(@1 IS NULL)"));
    }
 public void SetUp ()
 {
   _sqlIsNullExpression = new SqlIsNullExpression (Expression.Constant(2));
 }
    public Expression VisitSqlIsNullExpression (SqlIsNullExpression expression)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);

      var baseVisitedExpression = (SqlIsNullExpression) base.VisitExtensionExpression (expression);

      var expressionWithEntityComparisonResolved = _entityIdentityResolver.ResolvePotentialEntityComparison (baseVisitedExpression);
      var result = _compoundComparisonSplitter.SplitPotentialCompoundComparison (expressionWithEntityComparisonResolved);

      if (baseVisitedExpression != result)
        return VisitExpression (result);

      return baseVisitedExpression;
    }
    public void ResolvePotentialEntityComparison_SqlIsNullExpression_NonEntities_ReturnsSameExpression ()
    {
      var sqlIsNullExpression = new SqlIsNullExpression (Expression.Constant (0));

      var result = _entityIdentityResolver.ResolvePotentialEntityComparison (sqlIsNullExpression);

      Assert.That (result, Is.SameAs (sqlIsNullExpression));
    }
    public SqlIsNullExpression ResolvePotentialEntityComparison (SqlIsNullExpression isNullExpression)
    {
      var newExpression = ResolvePotentialEntity (isNullExpression.Expression);

      if (newExpression != isNullExpression.Expression)
        return new SqlIsNullExpression (newExpression);

      return isNullExpression;
    }
    public void VisitSqlIsNullExpression_AppliesSingleValueSemantics_AllowsSingleValue ()
    {
      var sqlIsNullExpressionWithValue = new SqlIsNullExpression (Expression.Constant (1));

      var resultWithValue = _valueRequiredVisitor.VisitSqlIsNullExpression (sqlIsNullExpressionWithValue);

      Assert.That (resultWithValue, Is.SameAs (sqlIsNullExpressionWithValue));
    }