public void GivenExpressionWithSingleTableExpression_WhenReordered_ReturnsOriginalExpression() { var inputExpression = SqlRootExpression.WithTableExpressions( new TableExpression(null, null, null, TableExpressionKind.Normal)); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(NormalizedPredicateReorderer.Instance); Assert.Equal(inputExpression, visitedExpression); }
public void GivenExpressionWithNoMissingParameterExpression_WhenVisited_OriginalExpressionReturned() { var tableExpressions = new List <TableExpression> { new TableExpression(null, null, null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(MissingSearchParamVisitor.Instance); Assert.Equal(inputExpression, visitedExpression); }
public void GivenExpressionWithMulthMultipleTableExpressions_WhenReordered_IncludeExpressionReturnedLast() { var tableExpressions = new List <TableExpression> { new TableExpression(new IncludeQueryGenerator(), null, null, TableExpressionKind.Include), new TableExpression(null, null, null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(NormalizedPredicateReorderer.Instance); Assert.Collection(visitedExpression.TableExpressions, new[] { 1, 0 }.Select <int, Action <TableExpression> >(x => e => Assert.Equal(tableExpressions[x], e)).ToArray()); }
public void GivenExpressionWithMulthMultipleTableExpressions_WhenReordered_DenormilizedExpressionReturnedFirst() { var tableExpressions = new List <TableExpression> { new TableExpression(new ReferenceSearchParameterQueryGenerator(), NormalExpression, null, TableExpressionKind.Normal), new TableExpression(null, null, Expression.Equals(FieldName.String, null, "TestId"), TableExpressionKind.All), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(NormalizedPredicateReorderer.Instance); Assert.Collection(visitedExpression.TableExpressions, new[] { 1, 0 }.Select <int, Action <TableExpression> >(x => e => Assert.Equal(tableExpressions[x], e)).ToArray()); }
public void GivenExpressionWithMultipleTableExpressions_WhenReordered_MissingParameterExpressionReturnedBeforeNotExpression() { var tableExpressions = new List <TableExpression> { new TableExpression(null, NotExpression, null, TableExpressionKind.Normal), new TableExpression(null, new MissingSearchParameterExpression(new SearchParameterInfo("TestParam"), true), null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(NormalizedPredicateReorderer.Instance); Assert.Collection(visitedExpression.TableExpressions, new[] { 1, 0 }.Select <int, Action <TableExpression> >(x => e => Assert.Equal(tableExpressions[x], e)).ToArray()); }
public void GivenExpressionWithMissingParameterExpressionLast_WhenVisited_MissingParameterExpressionNegated() { var tableExpressions = new List <TableExpression> { new TableExpression(null, null, null, TableExpressionKind.Normal), new TableExpression(null, new MissingSearchParameterExpression(new SearchParameterInfo("TestParam"), true), null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(MissingSearchParamVisitor.Instance); Assert.Collection( visitedExpression.TableExpressions, e => { Assert.Equal(tableExpressions[0], e); }, e => { Assert.Equal(TableExpressionKind.NotExists, e.Kind); }); }
public void GivenExpressionWithMissingParameterExpression_WhenVisited_AllExpressionPrependedToExpressionList() { var tableExpressions = new List <TableExpression> { new TableExpression(null, new MissingSearchParameterExpression(new SearchParameterInfo("TestParam"), true), null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(MissingSearchParamVisitor.Instance); Assert.Collection( visitedExpression.TableExpressions, e => { Assert.Equal(TableExpressionKind.All, e.Kind); }, e => { Assert.NotNull(e.NormalizedPredicate as MissingSearchParameterExpression); }); Assert.Equal(tableExpressions.Count + 1, visitedExpression.TableExpressions.Count); }
public void GivenExpressionWithNotExpressionLast_WhenVisited_NotExpressionUnwrapped() { var subExpression = Expression.StringEquals(FieldName.TokenCode, 0, "TestValue123", false); var tableExpressions = new List <TableExpression> { new TableExpression(null, null, null, TableExpressionKind.Normal), new TableExpression(null, new SearchParameterExpression(new SearchParameterInfo("TestParam"), Expression.Not(subExpression)), null, TableExpressionKind.Normal), }; var inputExpression = SqlRootExpression.WithTableExpressions(tableExpressions); var visitedExpression = (SqlRootExpression)inputExpression.AcceptVisitor(NotExpressionRewriter.Instance); Assert.Collection( visitedExpression.TableExpressions, e => { Assert.Equal(tableExpressions[0], e); }, e => { ValidateNotExpression(subExpression, e); }); }