Skip to content

Commit

Permalink
Enable GearsOfWar query test suite
Browse files Browse the repository at this point in the history
Also fixing minor bugs that the tests have exposed
  • Loading branch information
maumar committed May 30, 2019
1 parent c5d15bc commit cfd0c70
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public override bool Equals(object obj)

private bool Equals(CaseExpression caseExpression)
=> base.Equals(caseExpression)
&& Operand == null ? caseExpression.Operand == null : Operand.Equals(caseExpression.Operand)
&& (Operand == null ? caseExpression.Operand == null : Operand.Equals(caseExpression.Operand))
&& WhenClauses.SequenceEqual(caseExpression.WhenClauses)
&& ElseResult == null ? caseExpression.ElseResult == null : ElseResult.Equals(caseExpression.ElseResult);
&& (ElseResult == null ? caseExpression.ElseResult == null : ElseResult.Equals(caseExpression.ElseResult));

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private bool Equals(InExpression inExpression)
=> base.Equals(inExpression)
&& Item.Equals(inExpression.Item)
&& Negated.Equals(inExpression.Negated)
&& Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values)
&& Subquery == null ? inExpression.Subquery == null : Subquery.Equals(inExpression.Subquery);
&& (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values))
&& (Subquery == null ? inExpression.Subquery == null : Subquery.Equals(inExpression.Subquery));

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;

namespace Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.SqlExpressions
{
public class OrderingExpression : Expression
public class OrderingExpression : Expression, IPrintable
{
#region Fields & Constructors
public OrderingExpression(SqlExpression expression, bool ascending)
Expand Down Expand Up @@ -62,6 +64,14 @@ public override int GetHashCode()
return hashCode;
}
}

#endregion

public void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.Visit(Expression);

expressionPrinter.StringBuilder.Append(Ascending ? "ASC" : "DESC");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,14 @@ public override void Print(ExpressionPrinter expressionPrinter)
expressionPrinter.StringBuilder.AppendLine("Projection Mapping:");
using (expressionPrinter.StringBuilder.Indent())
{
foreach (var projectionMappingEntry in _projectionMapping)
if (_projectionMapping != null)
{
expressionPrinter.StringBuilder.AppendLine();
expressionPrinter.StringBuilder.Append(projectionMappingEntry.Key + " -> ");
expressionPrinter.Visit(projectionMappingEntry.Value);
foreach (var projectionMappingEntry in _projectionMapping)
{
expressionPrinter.StringBuilder.AppendLine();
expressionPrinter.StringBuilder.Append(projectionMappingEntry.Key + " -> ");
expressionPrinter.Visit(projectionMappingEntry.Value);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -44,7 +45,7 @@ public override bool Equals(object obj)

private bool Equals(SqlConstantExpression sqlConstantExpression)
=> base.Equals(sqlConstantExpression)
&& Value.Equals(sqlConstantExpression.Value);
&& Value?.Equals(sqlConstantExpression.Value) == true;

public override int GetHashCode()
{
Expand All @@ -61,7 +62,32 @@ public override int GetHashCode()

public override void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.StringBuilder.Append(TypeMapping?.GenerateSqlLiteral(Value) ?? Value?.ToString() ?? "NULL");
Print(Value, expressionPrinter);
}

private void Print(
object value,
ExpressionPrinter expressionPrinter)
{
if (value is IEnumerable enumerable
&& !(value is string))
{
bool first = true;
foreach (var item in enumerable)
{
if (!first)
{
expressionPrinter.StringBuilder.Append(", ");
}

first = false;
Print(item, expressionPrinter);
}
}
else
{
expressionPrinter.StringBuilder.Append(TypeMapping?.GenerateSqlLiteral(value) ?? Value?.ToString() ?? "NULL");
}
}
}
}
Loading

0 comments on commit cfd0c70

Please sign in to comment.