Inheritance: Remotion.Linq.Clauses.Expressions.ExtensionExpression
    public void Initialization_Typed ()
    {
      var intExpression = new SqlLiteralExpression (10);
      Assert.That (intExpression.Value, Is.EqualTo (10));
      Assert.That (intExpression.Type, Is.EqualTo (typeof (int)));

      var nullableIntExpression = new SqlLiteralExpression (10, true);
      Assert.That (nullableIntExpression.Value, Is.EqualTo (10));
      Assert.That (nullableIntExpression.Type, Is.EqualTo (typeof (int?)));

      var longExpression = new SqlLiteralExpression (10L);
      Assert.That (longExpression.Value, Is.EqualTo (10L));
      Assert.That (longExpression.Type, Is.EqualTo (typeof (long)));

      var nullableLongExpression = new SqlLiteralExpression (10L, true);
      Assert.That (nullableLongExpression.Value, Is.EqualTo (10L));
      Assert.That (nullableLongExpression.Type, Is.EqualTo (typeof (long?)));

      var stringExpression = new SqlLiteralExpression ("a");
      Assert.That (stringExpression.Value, Is.EqualTo ("a"));
      Assert.That (stringExpression.Type, Is.EqualTo (typeof (string)));

      Assert.That (() => new SqlLiteralExpression (null), Throws.TypeOf<ArgumentNullException>());

      var doubleExpression = new SqlLiteralExpression (10.12);
      Assert.That (doubleExpression.Value, Is.EqualTo (10.12));
      Assert.That (doubleExpression.Type, Is.EqualTo (typeof (double)));

      var nullableDoubleExpression = new SqlLiteralExpression (10.12, true);
      Assert.That (nullableDoubleExpression.Value, Is.EqualTo (10.12));
      Assert.That (nullableDoubleExpression.Type, Is.EqualTo (typeof (double?)));
    }
 public void SetUp ()
 {
   var leftExpression = Expression.Constant ("left");
   var rightExpression = Expression.Constant ("right");
   var escapeExpression = new SqlLiteralExpression (@"\");
   _likeExpression = new SqlLikeExpression (leftExpression, rightExpression, escapeExpression);
 }
    public void SetUp ()
    {
      var item1 = new SqlLiteralExpression (13);
      var item2 = Expression.Constant (12);
      _items = new Expression[] { item1, item2 };

      _collectionExpression = new SqlCollectionExpression (typeof (List<int>), _items);
    }
    public void VisitBinaryExpression_RevisitingTerminatesAfterInnerChanges_WithoutOuterChanges ()
    {
      var left = Expression.Constant (0);
      var right = Expression.Constant (1);
      var binary = Expression.Equal (left, right);

      var fakeResolvedLeft = new SqlLiteralExpression (2);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (left)).Return (fakeResolvedLeft);
      var fakeResolvedRight = new SqlLiteralExpression (3);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (right)).Return (fakeResolvedRight);

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

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

      // No revisiting

      var result = _visitor.VisitExpression (binary);

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

      Assert.That (result, Is.AssignableTo<BinaryExpression> ());
      Assert.That (((BinaryExpression) result).Left, Is.SameAs (fakeResolvedLeft));
      Assert.That (((BinaryExpression) result).Right, Is.SameAs (fakeResolvedRight));
    }
    public void VisitBinaryExpression()
    {
      var left = Expression.Constant (0);
      var right = Expression.Constant (1);
      var binary = Expression.Equal (left, right);

      var fakeResolvedLeft = new SqlLiteralExpression (2);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (left)).Return (fakeResolvedLeft);
      var fakeResolvedRight = new SqlLiteralExpression (3);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (right)).Return (fakeResolvedRight);

      var fakeResolvedEntityComparison = Expression.Equal (Expression.Constant (2), Expression.Constant (3));
      _entityIdentityResolverMock
          .Expect (
              mock => mock.ResolvePotentialEntityComparison (
                  Arg<BinaryExpression>.Matches (e => e.Left == fakeResolvedLeft && e.Right == fakeResolvedRight)))
          .Return (fakeResolvedEntityComparison);

      var fakeSplitComparison = Expression.Equal (Expression.Constant (4), Expression.Constant (5));
      _compoundComparisonSplitterMock
          .Expect (mock => mock.SplitPotentialCompoundComparison (fakeResolvedEntityComparison))
          .Return (fakeSplitComparison);

      // Result is revisited
      _resolverMock.Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeSplitComparison.Left)).Return (fakeSplitComparison.Left);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeSplitComparison.Right)).Return (fakeSplitComparison.Right);
      _entityIdentityResolverMock.Expect (mock => mock.ResolvePotentialEntityComparison (fakeSplitComparison)).Return (fakeSplitComparison);
      _compoundComparisonSplitterMock.Expect (mock => mock.SplitPotentialCompoundComparison (fakeSplitComparison)).Return (fakeSplitComparison);

      var result = _visitor.VisitExpression (binary);

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

      Assert.That (result, Is.SameAs (fakeSplitComparison));
    }
 public void SetUp ()
 {
   _literalExpression = new SqlLiteralExpression (10);
 }
    public void ConvertToSqlTable_StreamedSingleValueInfo_NoSqlTables ()
    {
      var selectProjection = Expression.Constant (new Cook ());
      var topExpression = new SqlLiteralExpression (2);
      var sqlStatement =
          new SqlStatementBuilder
          {
            DataInfo = new StreamedSingleValueInfo (typeof (Cook), false),
            SelectProjection = selectProjection,
            TopExpression = topExpression
          }.GetSqlStatement ();
      var expression = new SqlSubStatementExpression (sqlStatement);

      var result = expression.ConvertToSqlTable ("q0");

      Assert.That (result.JoinSemantics, Is.EqualTo (JoinSemantics.Inner));
      Assert.That (result.TableInfo.GetResolvedTableInfo ().TableAlias, Is.EqualTo ("q0"));
      Assert.That (result.TableInfo, Is.TypeOf (typeof (ResolvedSubStatementTableInfo)));

      var newSubStatement = ((ResolvedSubStatementTableInfo) result.TableInfo).SqlStatement;
      Assert.That (newSubStatement.TopExpression, Is.SameAs (topExpression));
    }
    public void VisitSqlIsNotNullExpression_RevisitingTerminatesAfterInnerChanges_WithoutOuterChanges  ()
    {
      var inner = Expression.Constant (0);
      var isNotNullExpression = new SqlIsNotNullExpression (inner);

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

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


      // No revisiting

      var result = _visitor.VisitExpression (isNotNullExpression);

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

      Assert.That (result, Is.TypeOf<SqlIsNotNullExpression> ());
      Assert.That (((SqlIsNotNullExpression) result).Expression, Is.SameAs (fakeResolvedInner));
    }
    public void VisitSqlInExpression ()
    {
      var left = Expression.Constant (0);
      var right = Expression.Constant (1);
      var inExpression = new SqlInExpression (left, right);

      var fakeResolvedLeft = new SqlLiteralExpression (2);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (left)).Return (fakeResolvedLeft);
      var fakeResolvedRight = new SqlLiteralExpression (3);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (right)).Return (fakeResolvedRight);

      var fakeResolvedInExpression = new SqlInExpression (Expression.Constant (4), Expression.Constant (5));
      _entityIdentityResolverMock
          .Expect (
              mock => mock.ResolvePotentialEntityComparison (
                  Arg<SqlInExpression>.Matches (e => e.LeftExpression == fakeResolvedLeft && e.RightExpression == fakeResolvedRight)))
          .Return (fakeResolvedInExpression);
      
      // Result is revisited
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeResolvedInExpression.LeftExpression))
          .Return (fakeResolvedInExpression.LeftExpression);
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeResolvedInExpression.RightExpression))
          .Return (fakeResolvedInExpression.RightExpression);
      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntityComparison (fakeResolvedInExpression))
          .Return (fakeResolvedInExpression);

      var result = _visitor.VisitExpression (inExpression);

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

      Assert.That (result, Is.SameAs (fakeResolvedInExpression));
    }
    public void VisitSqlExistsExpression ()
    {
      var inner = Expression.Constant (0);
      var existsExpression = new SqlExistsExpression (inner);

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

      var fakeResolvedEntityIdentity = Expression.Constant (1);
      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntity (fakeResolvedInner))
          .Return (fakeResolvedEntityIdentity);

      // Result is revisited
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (fakeResolvedEntityIdentity)).Return (fakeResolvedEntityIdentity);
      _entityIdentityResolverMock.Expect (mock => mock.ResolvePotentialEntity (fakeResolvedEntityIdentity)).Return (fakeResolvedEntityIdentity);

      var result = _visitor.VisitExpression (existsExpression);

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

      Assert.That (result, Is.TypeOf<SqlExistsExpression>());
      Assert.That (((SqlExistsExpression) result).Expression, Is.SameAs (fakeResolvedEntityIdentity));
    }
    public void VisitSqlLiteralExpression_Empty ()
    {
      var expression = new SqlLiteralExpression ("");
      SqlGeneratingExpressionVisitor.GenerateSql (
          expression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText(), Is.EqualTo ("''"));
    }
    public void VisitSqlLiteralExpression_Double_CultureAgnostic ()
    {
      var expression = new SqlLiteralExpression (1.1);
      Assert.That (expression.Value.ToString(), Is.Not.EqualTo ("1.1"));

      SqlGeneratingExpressionVisitor.GenerateSql (expression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText (), Is.EqualTo ("1.1"));
    }
    public void VisitLiteralExpression ()
    {
      var expression = new SqlLiteralExpression (5);

      SqlGeneratingExpressionVisitor.GenerateSql (expression, _commandBuilder, _stageMock);

      Assert.That (_commandBuilder.GetCommandText(), Is.EqualTo ("5"));
      Assert.That (_commandBuilder.GetCommandParameters(), Is.Empty);
    }
    public void VisitSqlLiteralExpression ()
    {
      var expression = new SqlLiteralExpression (1);

      var result = _predicateRequiredVisitor.VisitSqlLiteralExpression (expression);

      Assert.That (result, Is.SameAs (expression));
    }
    public void VisitNamedExpression ()
    {
      var innerExpression = Expression.Constant (0);
      var namedExpression = new NamedExpression ("Name", innerExpression);

      var fakeResolvedInnerExpression = new SqlLiteralExpression (1);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (innerExpression)).Return (fakeResolvedInnerExpression);

      var fakeCombinedExpression = new NamedExpression ("Name2", Expression.Constant (2));
      _namedExpressionCombinerMock
          .Expect (mock => mock.ProcessNames (Arg<NamedExpression>.Matches (e => e.Name == "Name" && e.Expression == fakeResolvedInnerExpression)))
          .Return (fakeCombinedExpression);

      // Result is revisited.
      var fakeResolvedInnerExpression2 = new SqlLiteralExpression (3);
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression ((ConstantExpression) fakeCombinedExpression.Expression))
          .Return (fakeResolvedInnerExpression2);
      _namedExpressionCombinerMock
          .Expect (mock => mock.ProcessNames (Arg<NamedExpression>.Matches (e => e.Name == "Name2" && e.Expression == fakeResolvedInnerExpression2)))
          .Return (null)
          .WhenCalled (mi => mi.ReturnValue = mi.Arguments[0]);

      var result = _visitor.VisitExpression (namedExpression);

      _resolverMock.VerifyAllExpectations ();
      _namedExpressionCombinerMock.VerifyAllExpectations ();

      Assert.That (result, Is.TypeOf<NamedExpression> ());
      Assert.That (((NamedExpression) result).Name, Is.EqualTo ("Name2"));
      Assert.That (((NamedExpression) result).Expression, Is.SameAs (fakeResolvedInnerExpression2));
    }
    public void VisitNamedExpression_RevisitingTerminatesAfterInnerChanges_WithoutOuterChanges ()
    {
      var innerExpression = Expression.Constant (0);
      var namedExpression = new NamedExpression ("Name", innerExpression);

      var fakeResolvedInnerExpression = new SqlLiteralExpression (1);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (innerExpression)).Return (fakeResolvedInnerExpression);

      _namedExpressionCombinerMock
          .Expect (mock => mock.ProcessNames (Arg<NamedExpression>.Is.Anything))
          .Return (null)
          .WhenCalled (mi => mi.ReturnValue = mi.Arguments[0]);

      // No revisiting

      var result = _visitor.VisitExpression (namedExpression);

      _resolverMock.VerifyAllExpectations ();
      _namedExpressionCombinerMock.VerifyAllExpectations ();

      Assert.That (result, Is.TypeOf<NamedExpression> ());
      Assert.That (((NamedExpression) result).Name, Is.EqualTo ("Name"));
      Assert.That (((NamedExpression) result).Expression, Is.SameAs (fakeResolvedInnerExpression));
    }
    public void ResolveMemberAccess ()
    {
      var sourceExpression = new SqlColumnDefinitionExpression (typeof (Cook), "c", "Substitution", false);
      var memberInfo = typeof (Cook).GetProperty ("Name");
      var fakeResolvedExpression = new SqlLiteralExpression ("Hugo");

      _resolverMock
          .Expect (mock => mock.ResolveMemberExpression (sourceExpression, memberInfo))
          .Return (fakeResolvedExpression);
      _resolverMock.Replay();

      var result = _stage.ResolveMemberAccess (sourceExpression, memberInfo, _resolverMock, _mappingResolutionContext);

      _resolverMock.VerifyAllExpectations();
      Assert.That (result, Is.SameAs (fakeResolvedExpression));
    }
    public void VisitSqlExistsExpression_RevisitingTerminatesAfterInnerChanges_WithoutOuterChanges ()
    {
      var inner = Expression.Constant (0);
      var existsExpression = new SqlExistsExpression (inner);

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

      _entityIdentityResolverMock
          .Expect (mock => mock.ResolvePotentialEntity (fakeResolvedInner))
          .Return (fakeResolvedInner);

      // No revisiting!

      var result = _visitor.VisitExpression (existsExpression);

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

      Assert.That (result, Is.TypeOf<SqlExistsExpression> ());
      Assert.That (((SqlExistsExpression) result).Expression, Is.SameAs (fakeResolvedInner));
    }
    public void VisitMemberExpression ()
    {
      var memberInfo = typeof (Cook).GetProperty ("ID");
      var expression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook));
      var memberExpression = Expression.MakeMemberAccess (expression, memberInfo);

      var fakeResolvedExpression = new SqlLiteralExpression (1);
      _stageMock
          .Expect (mock => mock.ResolveMemberAccess (expression, memberInfo, _resolverMock, _mappingResolutionContext))
          .Return (fakeResolvedExpression);
      _stageMock.Replay();

      var result = ResolvingExpressionVisitor.ResolveExpression (memberExpression, _resolverMock, _stageMock, _mappingResolutionContext, _generator);

      _stageMock.VerifyAllExpectations();
      Assert.That (result, Is.SameAs (fakeResolvedExpression));
    }
    public void VisitSqlIsNotNullExpression ()
    {
      var inner = Expression.Constant (0);
      var isNotNullExpression = new SqlIsNotNullExpression (inner);

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

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

      var fakeSplitCompoundComparison = new SqlIsNotNullExpression (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 (isNotNullExpression);

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

      Assert.That (result, Is.SameAs (fakeSplitCompoundComparison));
    }
    public void VisitMemberExpression_ResolvesSourceExpression ()
    {
      var memberInfo = typeof (Cook).GetProperty ("ID");
      var expression = Expression.Constant (null, typeof (Cook));
      var memberExpression = Expression.MakeMemberAccess (expression, memberInfo);

      var fakeResolvedSourceExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook));
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression (expression))
          .Return (fakeResolvedSourceExpression);
      _resolverMock.Replay();

      var fakeResolvedExpression = new SqlLiteralExpression (1);
      _stageMock
          .Expect (mock => mock.ResolveMemberAccess (fakeResolvedSourceExpression, memberInfo, _resolverMock, _mappingResolutionContext))
          .Return (fakeResolvedExpression);
      _stageMock.Replay();

      _visitor.VisitExpression (memberExpression);

      _resolverMock.VerifyAllExpectations();
      _stageMock.VerifyAllExpectations();
    }
 public Expression VisitSqlLiteralExpression (SqlLiteralExpression expression)
 {
   // No children.
   return expression;
 }
    public void VisitMemberExpression_RevisitsResult ()
    {
      var memberInfo = typeof (Cook).GetProperty ("ID");
      var expression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression (typeof (Cook));
      var memberExpression = Expression.MakeMemberAccess (expression, memberInfo);

      var fakeResult1 = Expression.Constant (1);
      var fakeResult2 = new SqlLiteralExpression (7);
      _stageMock
          .Expect (mock => mock.ResolveMemberAccess (expression, memberInfo, _resolverMock, _mappingResolutionContext))
          .Return (fakeResult1);
      _resolverMock
          .Expect (mock => mock.ResolveConstantExpression (fakeResult1))
          .Return (fakeResult2);

      var result = _visitor.VisitExpression (memberExpression);

      _stageMock.VerifyAllExpectations();
      _resolverMock.VerifyAllExpectations();
      Assert.That (result, Is.SameAs (fakeResult2));
    }
    public void VisitTypeBinaryExpression ()
    {
      var expression = Expression.Constant ("select");
      var typeBinaryExpression = Expression.TypeIs (expression, typeof (Chef));
      var resolvedTypeExpression = Expression.Constant ("resolved");
      var resolvedRevisitedResult = new SqlLiteralExpression (0);

      _resolverMock.Expect (mock => mock.ResolveConstantExpression (expression))
          .Return (expression);
      _resolverMock.Expect (mock => mock.ResolveTypeCheck (expression, typeof (Chef)))
          .Return (resolvedTypeExpression);
      _resolverMock.Expect (mock => mock.ResolveConstantExpression (resolvedTypeExpression))
          .Return (resolvedRevisitedResult);
      _resolverMock.Replay();

      var result = _visitor.VisitExpression (typeBinaryExpression);

      _resolverMock.VerifyAllExpectations();

      Assert.That (result, Is.SameAs (resolvedRevisitedResult));
    }
 public void ToString_String ()
 {
   var literalExpression = new SqlLiteralExpression ("test");
   Assert.That (literalExpression.ToString (), Is.EqualTo ("\"test\""));
 }