MyTested.AspNetCore.Mvc icon indicating copy to clipboard operation
MyTested.AspNetCore.Mvc copied to clipboard

How to disable dbContext replace with MyTested.AspNetCore.EntityFrameworkCore

Open grinay opened this issue 3 years ago • 2 comments

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?

grinay avatar Nov 12 '21 21:11 grinay

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

ivaylokenov avatar Nov 24 '21 14:11 ivaylokenov

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

grinay avatar Nov 25 '21 17:11 grinay