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

Removed generic type constraint in extension methods #62

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tiwahu
Copy link

@tiwahu tiwahu commented Aug 24, 2022

PR Details

Description

  • Allows TEntity to be a value type.

The extension methods had a generic type constraint that prevented IQueryable<T> where T is a value type from being mocked.

I wasn't sure if the reference type constraint was intentional, an oversight, or leftover from older code. I successfully used the following locally to work around it and figured other could benefit:

var data = new TestAsyncEnumerableEfCore<long>(new[] { 42L });

Related Issue

How Has This Been Tested

  • All existing tests passed.
  • Locally used the code called by the extension method and it worked with a long for TEntity.

Checklist

  • My code follows the code style of this project.
  • I have added tests to cover my changes.

    All tests passed. Hopefully covered by existing test suite...but I'll check that! Maybe we should make a value type test. ;)

  • All new and existing tests passed.

- Allows TEntity to be a value type.
@romantitov
Copy link
Owner

hello @tiwahu sorry for the late answer. Thanks for your contribution.
Could you provide a bit more explanation, what kind of problem you are trying to solve by using long as an entity?
Could you please also add to the PR test cases for your specific cases with value types and I will be happy to include your changes to the next release.

@tiwahu
Copy link
Author

tiwahu commented May 15, 2024

@romantitov, sorry for such a late reply! This library is pretty awesome and simplified tests where we were starting to do it ourselves.

At some point we encountered a scenario where the TEntity, in an IQueryable<TEntity> that we wanted to mock and use async methods, was a value type. In our case, it was a long, but it could have been any value type (e.g., a database query that just returned a column of 64-bit integers).

I did something manual to work around going through the extension method, which has the complier restriction. The TestAsyncEnumerableEfCore<T> doesn't have the same class restriction for T, so it seemed like it would work, and it did. Is there a reason for the class restriction in the extension methods?

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 this pull request may close these issues.

None yet

2 participants