EF Core 3.0 Integration Tests Access Db From In Memory Provider
See original GitHub issueI’m pulling the exact sample shown here: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.0
I’m trying to pull back out the Db Context inside a Test so I can add/delete some records.
[Fact]
public async Task Post_DeleteAllMessagesHandler_ReturnsRedirectToRoot()
{
// this bombs
var db = _factory.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
}
Attached is the code sample:
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Integration tests in ASP.NET Core
ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.
Read more >Unit Tests vs Integration tests: Entity Framework Core In ...
EF Core's InMemory provider is not 100% the same as testing with a real database. In fact, there are quite a few differences....
Read more >Integration testing in ASP.NET Core with EF Sqlite and ...
A simple example how to do integration testing in ASP.NET Core with Entity Framework Core Sqlite and InMemory Provider.
Read more >Integration testing with EF Core, part 1
The aim of the in memory database provider is to simplify testing and if you compare what it takes now to write test...
Read more >Verify data in tests with ASP.NET Core and EF Core in memory
If you follow the official guidance on doing integration tests in ASP.NET Core 2.1, then you can use either an in-memory database provider, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aherrick - Can you also describe what you is the error you are getting.
@aherrick If you are following the exact steps from a walkthrough and it does’t work, then please file an issue on that walkthrough. There is a button on the bottom of the walkthrough page to do this.
The stack trace you posted does not contain any EF code. It looks to me, as @smitpatel said, that the D.I. container is not setup correctly or is being used correctly. How D.I. is intended to be used for this walkthrough is something that should at least initially be addressed by the author of the walkthrough.