Entity Framework Context Mocking

entity-framework mocking unit-testing

Question

I want to fake the database environment within my unit tests since I use the entity framework to access my database and I want to test my middle tier classes independently of actual data. I am aware that I am not the first to inquire about this A mock Entity Framework model is used., but after doing some research, I have a hunch that the context may be instantiated using just the model's information.

Has anybody succeeded in doing this?

1
19
5/23/2017 12:14:10 PM

Accepted Answer

There's an excellent article on it and unit testing EF in general, but you can also accomplish it with only metadata, here.

6
4/2/2009 4:15:54 PM

Popular Answer

Using the Repository style is a well-known method for doing this. This serves as a wrapper over your actual data access code and gives you somewhere to insert test duplicates.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow