Open ajcvickers opened 5 years ago
Maybe also document which features need to be implemented "manually", for example I had to specify a standard default value for concurrency tokens, a converter for concurrency tokens, a comparer for concurrency tokens and a converter for datetimeoffssets
Documentation on Registering with Dependency Injection and maintaining\ re-hydrating state across multiple tests would be useful as well.
I only just spotted this and haven't tried it, but perhaps it's made for this scenario: Sharable in-memory
Data Source=Sharable;Mode=Memory;Cache=Shared
It's probably obvious, but there is no mention which Nuget package to install if someone want to use EF Sqlite in-memory feature.
@Ninjanaut It doesn't require a different NuGet package; it's a feature built in to SQLite.
I have created method in base test class:
protected AppDbContext GetDbContext() => new AppDbContext(_dbContextOptions);
So any time I need new context I call it.
public async Task HasAccessAsync()
{
var dbContext = GetDbContext();
var users = dbContext.Users.ToList();
var service = dbContext.Services.Include(s => s.Users).Include(s => s.Groups).First();
Assert.True(await _service.HasAccessAsync<Service>(users[0].Id, service.Id));
Assert.True(await _service.HasAccessAsync<Service>(users[1].Id, service.Id));
Assert.False(await _service.HasAccessAsync<Service>(users[2].Id, service.Id));
}
I have came up to the statement that I need fresh context most of the time to avoid caching in Local
and pass missing .Include()
calls. Are there some more complicated connection management tasks?
the documentation (https://docs.microsoft.com/en-us/ef/core/testing/sqlite) is IMHO misleading re using SQLite in-memory database in conjunction with .AddDbContext()
method, see #25204
It's probably obvious, but there is no mention which Nuget package to install if someone want to use EF Sqlite in-memory feature.
I agree. For someone new to sqlite just doing a Nuget Package Manager search for sqlite returns a lot of results. It really wouldn't hurt to note that Microsoft.EntityFrameworkCore.Sqlite is required.
For example, some sugar to make it easier to keep a connection open across multiple context instances.
@divega @bricelam I believe you guys have some additional thoughts here--maybe link some of the information from Brice's blog?