Removed generic type constraint in extension methods
PR Details
Description
- Allows
TEntityto 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
longforTEntity.
Checklist
- [X] 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. ;)
- [X] All new and existing tests passed.
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.
@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?