question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core 3.0 Integration Tests Access Db From In Memory Provider

See original GitHub issue

I’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:

IntegrationTestsSample.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Nov 14, 2019

@aherrick - Can you also describe what you is the error you are getting.

0reactions
ajcvickerscommented, Nov 15, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found