How can I access the dbcontext of an in memory database inside an integration test?
I have followed the code here: https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.2#customize-webapplicationfactory
and have a similar test to:
public class IndexPageTests :
IClassFixture<CustomWebApplicationFactory<RazorPagesProject.Startup>>
{
private readonly HttpClient _client;
private readonly CustomWebApplicationFactory<RazorPagesProject.Startup>
_factory;
public IndexPageTests(
CustomWebApplicationFactory<RazorPagesProject.Startup> factory)
{
_factory = factory;
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false
});
}
In this IndexPageTests is it possible to access the in-memory dbcontext?
I have tried
using (var context = new ApplicationDbContext(???))
I need to access data from tables i had previously seeded from CustomWebApplicationFactory
but not sure what to put for the options
factory.Server.Host.Services.GetService<ApplicationDbContext>()
– Tessy