ivaylokenov / MyTested.AspNetCore.Mvc

Fluent testing library for ASP.NET Core MVC.
https://docs.mytestedasp.net/
Other
1.72k stars 176 forks source link

How to disable dbContext replace with MyTested.AspNetCore.EntityFrameworkCore #394

Open grinay opened 2 years ago

grinay commented 2 years ago

I faced into next problem. I'm replacing dbContext to InMemory by myself in TechStartup.cs in method ConfigureTestServices. Then in my startup class, I have a method which seeding some data into db. But later on, when I execute the controller method by Db replaced by MyTested.AspNetCore.EntityFrameworkCore to its in-memory DB context. Can you advice how to avoid it?

ivaylokenov commented 2 years ago

@grinay Why do you replace the DbContext by yourself? What do you want to accomplish? Do you just want to seed global data for every test case? Is that the scenario here?

grinay commented 2 years ago

@ivaylokenov yes, basically in the startup class on the first run seeding some data into the database, eventually this data isn't available in dB for a test. Also in some scenarios, we are testing against the real SQL database, to test constraints, etc. And if I want to use data extension to check data in DB, i need to install mytested entity framework extension, which replaces DbContext to in-memory, and I am unable to find an option to disable this.