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

error TestQueryable when mock nhibernate query with multiple fetches #20

Closed
ivan-luxoft opened this issue Sep 20, 2024 · 1 comment · Fixed by #21
Closed

error TestQueryable when mock nhibernate query with multiple fetches #20

ivan-luxoft opened this issue Sep 20, 2024 · 1 comment · Fixed by #21

Comments

@ivan-luxoft
Copy link
Contributor

ivan-luxoft commented Sep 20, 2024

I have a problem with mocking query by TestQueryable
the next request is failed:

repository.Create().GetQueryable()
                                  .FetchMany(x => x.InternalCollection)
                                  .ThenFetchMany(x => x.InternalInternalCollection)
                                  .Single(x => x.Id == id)

the TestQueryable fails in method AvoidFetch because the one of the fetches doenst have node.Arguments[0] as MethodCallExpression, it has a constant

I fix it locally as

private static Expression AvoidFetch(MethodCallExpression node) =>
  !ExpressionTreeModifier.IsFetchMethod(node.Method)
                    ? (Expression)node
                    : node.Arguments[0] is MethodCallExpression methodNode
                        ? ExpressionTreeModifier.AvoidFetch(methodNode)
                        : node.Arguments[0];

I'm not sure that it is the right way, but it works for me, and all my tests/queryable mocks

@ivan-luxoft ivan-luxoft changed the title error TestQueryable, mock nhibernate with multiple fetches error TestQueryable when mock nhibernate with multiple fetches Sep 20, 2024
@ivan-luxoft ivan-luxoft changed the title error TestQueryable when mock nhibernate with multiple fetches error TestQueryable when mock nhibernate query with multiple fetches Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@ivan-luxoft and others