From 39129022ed0d03d6e2fe7fbf786d0bc0674981a9 Mon Sep 17 00:00:00 2001 From: Ross Lovas Date: Thu, 2 Feb 2023 17:14:59 +1030 Subject: [PATCH] Include details in QueryTranslator NotSupportedExceptions --- .../QueryableIntegrationFixture.cs | 22 +++++++++++++++++++ .../Advanced/Queryable/QueryTranslator.cs | 10 ++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/source/Nevermore.IntegrationTests/QueryableIntegrationFixture.cs b/source/Nevermore.IntegrationTests/QueryableIntegrationFixture.cs index 77413406..fa9375d7 100644 --- a/source/Nevermore.IntegrationTests/QueryableIntegrationFixture.cs +++ b/source/Nevermore.IntegrationTests/QueryableIntegrationFixture.cs @@ -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().Prepend(new()).ToListAsync(); + + await runQueryWithUnsupportedMethod.Should().ThrowAsync(); + } + + [Test] + public async Task UnsupportedWhereExpression_ShouldThrowNotSupportedException() + { + using var t = Store.BeginTransaction(); + + var runQueryWithUnsupportedWhereExpression = + async () => _ = await t.Queryable().Where(_ => "".IsNormalized()).ToListAsync(); + + await runQueryWithUnsupportedWhereExpression.Should().ThrowAsync(); + } } } \ No newline at end of file diff --git a/source/Nevermore/Advanced/Queryable/QueryTranslator.cs b/source/Nevermore/Advanced/Queryable/QueryTranslator.cs index 63813ddd..fdaaee82 100644 --- a/source/Nevermore/Advanced/Queryable/QueryTranslator.cs +++ b/source/Nevermore/Advanced/Queryable/QueryTranslator.cs @@ -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}"); } } @@ -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) @@ -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) @@ -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) @@ -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);