0

Im using the entity framework 4.1 and have followed a tutorial to fake the dbcontext to mock and do unit tests. Everything works as expected with this. ive amended the original dbcontext to return idbset's however when i recreated my model it overwrote this. This is to be expected i suppose but wondered whether there is away i can stop this happening. Any ideas?

Richard Banks
  • 2,946
  • 5
  • 34
  • 71
  • Please show us some code sample, specially how you are mocking the dbcontext. Thanks. – AD.Net Oct 04 '11 at 14:43
  • Why do you even try to mock context? It is wrong approach because it [will not help you to test your code](http://stackoverflow.com/questions/6766478/unit-testing-dbcontext) and according to [this interesting article](http://www.davesquared.net/2011/04/dont-mock-types-you-dont-own.html) (I got reference [here](http://stackoverflow.com/questions/7110981/the-repository-itself-is-not-usually-tested/7111748#7111748)) you should not mock types you don't own. – Ladislav Mrnka Oct 04 '11 at 15:44

2 Answers2

2

Probably the easiest approach is to replace the T4 templates that do the code generation with your own – copy the default templates into your project and adapt them to generate the code you want.

MSDN has an introduction: http://msdn.microsoft.com/en-us/data/gg558520

Richard
  • 106,783
  • 21
  • 203
  • 265
0

You can also use moles. But I like the t4 template better.

Cubicle.Jockey
  • 3,288
  • 1
  • 19
  • 31