I am trying to unit test a large database. My queries will use methods like FirstOrDefaultAsync(). This results in an exception of the DbSet does not implement IDbAsyncEnumerable. For the underlying issue, and a potential solution to it, see IDbAsyncEnumerable not implemented.
I am creating my test database as follows:
var options = new DbContextOptionsBuilder<MyDb>()
.UseInMemoryDatabase(databaseName: myName)
.Options;
return new MyDb(options);
But now for the problem -- the solution there involves overriding the DbSet class with a TestDbSet that implements the missing interface IDbAsyncEnumerable. So I need my Db class to return a TestDbSet for all of the entities. The number is large, and furthermore, the db class is often regenerated (database first).
One possibility I noticed is the method
DbContextOptionsBuilder.ReplaceService
That certainly looks intriguing -- is whatever generates the DbSet objects a "service" that one can replace? If I can tell it to always return a TestDbSet instead of a DbSet, that would solve my problem. But I can't find any documentation of what the "services" are that could be replaced by this method.