-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EFCore.QueryRepository.Tests Project added.
- Loading branch information
1 parent
2eef4a5
commit 6d72934
Showing
4 changed files
with
75 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/EFCore.QueryRepository.Tests/EFCore.QueryRepository.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections; | ||
using System.Linq.Expressions; | ||
|
||
namespace EFCore.QueryRepository.Tests; | ||
|
||
public static class QueryableExtensions | ||
{ | ||
public static IQueryable<T> AsAsyncQueryable<T>(this IEnumerable<T> input) | ||
{ | ||
return new NotInDbSet<T>(input); | ||
} | ||
} | ||
|
||
public class NotInDbSet<T> : IQueryable<T>, IAsyncEnumerable<T>, IEnumerable<T>, IEnumerable | ||
{ | ||
private readonly List<T> _innerCollection; | ||
public NotInDbSet(IEnumerable<T> innerCollection) | ||
{ | ||
_innerCollection = innerCollection.ToList(); | ||
} | ||
|
||
|
||
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
return new AsyncEnumerator(GetEnumerator()); | ||
} | ||
|
||
public IEnumerator<T> GetEnumerator() | ||
{ | ||
return _innerCollection.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public class AsyncEnumerator : IAsyncEnumerator<T> | ||
{ | ||
private readonly IEnumerator<T> _enumerator; | ||
public AsyncEnumerator(IEnumerator<T> enumerator) | ||
{ | ||
_enumerator = enumerator; | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
return new ValueTask(); | ||
} | ||
|
||
public ValueTask<bool> MoveNextAsync() | ||
{ | ||
return new ValueTask<bool>(_enumerator.MoveNext()); | ||
} | ||
|
||
public T Current => _enumerator.Current; | ||
} | ||
|
||
public Type ElementType => typeof(T); | ||
public Expression Expression => Expression.Empty(); | ||
public IQueryProvider Provider => new EnumerableQuery<T>(Expression); | ||
} |