Skip to content

Commit

Permalink
Include details in QueryTranslator NotSupportedExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rosslovas committed Feb 2, 2023
1 parent c307a0f commit 3912902
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
22 changes: 22 additions & 0 deletions source/Nevermore.IntegrationTests/QueryableIntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,5 +1364,27 @@ public async Task ToListAsync()

customers.Select(c => c.LastName).Should().BeEquivalentTo("Apple");
}

[Test]
public async Task UnsupportedMethod_ShouldThrowNotSupportedException()
{
using var t = Store.BeginTransaction();

var runQueryWithUnsupportedMethod =
async () => _ = await t.Queryable<Customer>().Prepend(new()).ToListAsync();

await runQueryWithUnsupportedMethod.Should().ThrowAsync<NotSupportedException>();
}

[Test]
public async Task UnsupportedWhereExpression_ShouldThrowNotSupportedException()
{
using var t = Store.BeginTransaction();

var runQueryWithUnsupportedWhereExpression =
async () => _ = await t.Queryable<Customer>().Where(_ => "".IsNormalized()).ToListAsync();

await runQueryWithUnsupportedWhereExpression.Should().ThrowAsync<NotSupportedException>();
}
}
}
10 changes: 5 additions & 5 deletions source/Nevermore/Advanced/Queryable/QueryTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
return node;
}
default:
throw new NotSupportedException();
throw new NotSupportedException($"Specified method is not supported: {methodInfo}");
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ IWhereClause CreateWhereClause(Expression expression, bool invert = false)
return sqlBuilder.CreateWhere(fieldReference, UnarySqlOperand.Equal, !invert);
}

throw new NotSupportedException();
throw new NotSupportedException($"Where expression not supported: {expression}");
}

IWhereClause CreateMethodCallWhere(MethodCallExpression expression, bool invert = false)
Expand Down Expand Up @@ -262,7 +262,7 @@ IWhereClause CreateMethodCallWhere(MethodCallExpression expression, bool invert
}
}

throw new NotSupportedException();
throw new NotSupportedException($"Where expression not supported: {expression}");
}

IWhereClause CreateStringMethodWhere(MethodCallExpression expression, bool invert = false)
Expand All @@ -285,7 +285,7 @@ IWhereClause CreateStringMethodWhere(MethodCallExpression expression, bool inver
return sqlBuilder.CreateWhere(fieldReference, invert ? UnarySqlOperand.NotLike : UnarySqlOperand.Like, $"%{value}");
}

throw new NotSupportedException();
throw new NotSupportedException($"Where expression not supported: {expression}");
}

IWhereClause CreateBinaryWhere(BinaryExpression expression, bool invert = false)
Expand All @@ -312,7 +312,7 @@ IWhereClause CreateBinaryWhere(BinaryExpression expression, bool invert = false)
ExpressionType.LessThanOrEqual => invert ? UnarySqlOperand.GreaterThan : UnarySqlOperand.LessThanOrEqual,
ExpressionType.GreaterThan => invert ? UnarySqlOperand.LessThanOrEqual : UnarySqlOperand.GreaterThan,
ExpressionType.GreaterThanOrEqual => invert ? UnarySqlOperand.LessThan : UnarySqlOperand.GreaterThanOrEqual,
_ => throw new NotSupportedException()
_ => throw new NotSupportedException($"Where expression not supported: {expression}")
};

var (fieldReference, propertyType) = GetFieldReferenceAndType(expression.Left);
Expand Down

0 comments on commit 3912902

Please sign in to comment.