Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include details in QueryTranslator NotSupportedExceptions #245

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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