public void HandleResultOperator () { var resultOperator = new AnyResultOperator (); var sqlStatement = _sqlStatementBuilder.GetSqlStatement(); var fakePreparedSelectProjection = Expression.Constant (false); _stageMock .Expect (mock => mock.PrepareSelectExpression (Arg<Expression>.Matches (e => e is SqlExistsExpression), Arg.Is (_context))) .WhenCalled ( mi => { var selectProjection = (Expression) mi.Arguments[0]; Assert.That (selectProjection, Is.TypeOf (typeof (SqlExistsExpression))); var expectedExistsExpression = new SqlExistsExpression (new SqlSubStatementExpression (sqlStatement)); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedExistsExpression, selectProjection); }) .Return (fakePreparedSelectProjection); _handler.HandleResultOperator (resultOperator, _sqlStatementBuilder, _generator, _stageMock, _context); Assert.That (_sqlStatementBuilder.DataInfo, Is.TypeOf (typeof (StreamedScalarValueInfo))); Assert.That (((StreamedScalarValueInfo) _sqlStatementBuilder.DataInfo).DataType, Is.EqualTo (typeof (Boolean))); _stageMock.VerifyAllExpectations (); Assert.That (_sqlStatementBuilder.SelectProjection, Is.SameAs (fakePreparedSelectProjection)); }
public void HandleResultOperator () { var predicate = Expression.Constant (true); var preparedPredicate = Expression.Constant (false); var resultOperator = new AllResultOperator(predicate); var sqlStatement = _sqlStatementBuilder.GetSqlStatement(); var fakePreparedSelectProjection = Expression.Constant (false); _stageMock .Expect (mock => mock.PrepareWhereExpression ( Arg<Expression>.Matches(e => e.NodeType == ExpressionType.Not && (((UnaryExpression) e).Operand == predicate)), Arg<ISqlPreparationContext>.Matches(c=>c==_context))) .Return (preparedPredicate); _stageMock .Expect (mock => mock.PrepareSelectExpression (Arg<Expression>.Matches (e => e.NodeType == ExpressionType.Not), Arg.Is (_context))) .WhenCalled ( mi => { var selectProjection = (Expression) mi.Arguments[0]; var expectedSubStatement = new SqlStatementBuilder (sqlStatement) { WhereCondition = preparedPredicate }.GetSqlStatement(); var expectedExistsExpression = new SqlExistsExpression (new SqlSubStatementExpression (expectedSubStatement)); var expectedExpression = Expression.Not (expectedExistsExpression); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedExpression, selectProjection); }) .Return (fakePreparedSelectProjection); _stageMock.Replay(); _handler.HandleResultOperator (resultOperator, _sqlStatementBuilder, _generator, _stageMock, _context); _stageMock.VerifyAllExpectations (); Assert.That (_sqlStatementBuilder.DataInfo, Is.TypeOf (typeof (StreamedScalarValueInfo))); Assert.That (((StreamedScalarValueInfo) _sqlStatementBuilder.DataInfo).DataType, Is.EqualTo (typeof (Boolean))); Assert.That (_sqlStatementBuilder.SelectProjection, Is.SameAs (fakePreparedSelectProjection)); }
public Expression VisitSqlExistsExpression (SqlExistsExpression expression) { var baseVisitedExpression = (SqlExistsExpression) VisitExtensionExpression (expression); // Within an EXISTS query, an entity can be replaced by its IdentityExpression, so try to simplify it. var newInnerExpression = _entityIdentityResolver.ResolvePotentialEntity (baseVisitedExpression.Expression); if (newInnerExpression != baseVisitedExpression.Expression) return VisitExpression (new SqlExistsExpression (newInnerExpression)); return baseVisitedExpression; }
public void SetUp () { _sqlExistsExpression = new SqlExistsExpression (Expression.Constant ("test")); }
public Expression VisitSqlExistsExpression (SqlExistsExpression expression) { return VisitChildrenWithGivenSemantics (expression, SqlExpressionContext.ValueRequired); }
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 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 VisitExistsExpression () { var expression = new SqlExistsExpression (Expression.Constant ("test")); SqlGeneratingExpressionVisitor.GenerateSql (expression, _commandBuilder, _stageMock); var result = _commandBuilder.GetCommandText(); Assert.That (result, Is.EqualTo ("EXISTS(@1)")); }
public void VisitSqlExistsExpression_AllowsComplexValuesInChildren () { var expression = new SqlExistsExpression (CreateNewExpression()); var result = _predicateRequiredVisitor.VisitSqlExistsExpression (expression); Assert.That(result, Is.SameAs (expression)); }
public void VisitSqlExistsExpression () { var expression = new SqlExistsExpression (Expression.Constant (true)); var expectedResult = new SqlExistsExpression (new SqlConvertedBooleanExpression (Expression.Constant (1))); var result = _predicateRequiredVisitor.VisitSqlExistsExpression (expression); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result); }