Page 1 of 1

DbContext implement interface to leverage testability

Posted: Wed 21 Jan 2015 19:51
by otaviosoares
Hello

Is there a way of making my context implement an interface? It would certainly help me a lot by increasing testability, since I could, then, create FakeContext to use in my unit tests.

I tried doing so by creating another partial Context class and implementing my hard coded interface. But the generated context uses the DbSet concrete class instead of IDbSet abstraction, which makes my interface useless.

Please, let me know if I wasn't clear.

Thank you for your support.

Re: DbContext implement interface to leverage testability

Posted: Mon 26 Jan 2015 16:27
by Shalex
Please modify a predefined templates with an embedded T4 Editor which comes with Entity Developer to implement the needed code generation.

T4 documentation: