JonPSmith / EfCore.TestSupport

Tools for helping in unit testing applications that use Entity Framework Core
https://www.thereformedprogrammer.net/new-features-for-unit-testing-your-entity-framework-core-5-code/
Other
352 stars 53 forks source link

Use secrets.json #55

Closed tschennie closed 1 year ago

tschennie commented 1 year ago

For our integration tests, we created a DbContext like this:

DbContextOptions<TestDbContext>? options = this.CreateUniqueMethodOptions<TestDbContext>();
await using TestDbContext dbContext = new(options);

How is it possible to use the connection string from the secrets.json?

JonPSmith commented 1 year ago

Hi @tschennie,

The CreateUniqueMethodOptions<TContext> and other similar use the normal .NET access the project's configuration. This means if you Enable secret storage on the your test project, then you can set up a secret that overrides the appsettings.json version.

The connection strings names can be found here.