c# - IDbAsyncEnumerable not implemented -
I am trying to create FakeDbContext with FakeDbSet for unit testing.
But I get the error (see below). I am increasing the DBST so IDbAsyncEnumerable should generally be implemented. And when I implement it, it says that it has no use.
Exception:
System. Resident Operation Exception: Source IQueryable IDbAsyncEnumerable & lt; Conexio.Data does not apply to Entities.Conexio.ConexioContact & gt; The only sources implementing the IDBSync Enimereble can be used for the unit framework asynchronous tasks. For more details see http://go.microsoft.com/fwlink/?LinkId=287068 FakeDbSet Class:
Public Abstract Class FakeDbSet & Lt; TEntity & gt; : DBSET and lieutenant; Tentity & gt ;, IEnumerable & lt; TEntity & gt ;, IQueryable, IDbAsyncEnumerable & lt; TENTity & gt; Where tementi: unit, new () {#region Private Fields Private Redonially Observed Collection & lt; TEntity & gt; _items; Private Readonly IQueryable _query; #ndriven private field protected FakeDbSet () {_items = new Observeable Collection & lt; Tentity & gt; (); _query = _items.AsQueryable (); } Public expression expression {get_query.Expression {get; }} Public Type ElementType {get {return_query.ElementType; }} Public IQueryProvider Provider {get_query.provider; }} Public override TNTTT (TNTTYIT) {_items.Add (entity); Return unit; } Remove public override tenity (TNTity unit) {_items.Remove (unit); Return unit; } Public override tentite attachee (TNTity atity) {Switch (atity.org objectstate) {Case objectstate.Defined: _items.sverver}; _items.Add (unit); break; Case ObjectState. Deleted: _items.Remove (unit); break; Case ObjectState. Replaced: ObjectState case. Added: _items.Add (unit); break; Default: Delete the new argumentForm exception (); } Return unit; } Make a public override tenity () Return {New Tainty}; } Create Public Override TDerivedEntity & lt; TDerivedEntity & gt; () {Return Activator.CreateInstance & lt; TDerivedEntity & gt; (); } Public Override Observable Collection & lt; TEntity & gt; Get Local {Receive; }} IEnumerator & lt; TENTity & gt; IEnumerable & lt; TEntity & gt; .GetEnumerator () {Return _items.GetEnumerator (); } Type IQueryable.ElementType {get {return_items.AsQueryable (). ElementType; }} Get the expression IQueryable.Expression {get_items.AsQueryable (). Expression; }} IQueryProvider IQueryable.Provider {get {return_items.AsQueryable (). the provider; }} There is an abstract with code here in the last file in the abstract, this is where the error occurs.
The link given with the exception message () clearly mentions your scenario missing The component IDbAsyncQueryProvider that you should return from your provider property.
Just navigate through the link to come.
I can add a little bit, I will just quote the necessary words. Phrase:
To use the asynchronous query, we need to do a bit more work. If we try to use our Moq DbSet with the GetAllBlogsAyncc method, then we will get the following exception:
System. Legal Operation Exception: Source IQueryable IDbAsyncEnumerable does not apply only using sources that implement IDBsink Enimereble The unit framework can be done for asynchronous tasks. See for more information.
To use async methods, we need to create an in-memory DbAsyncQueryProvider to act on the async query. Since it would be possible to use a query provider MoQ, making a test double implementation in code is very easy. The code for this implementation is as follows:
etc ...
Comments
Post a Comment