views:

252

answers:

2

My apologies, I read this post:

http://stackoverflow.com/questions/316897/tdd-and-ado-net-entity-framework

But I don't think it covers what I'm looking for and other similar questions seem unanswered. So, forgive me if this has already been answered.

I have an application that I'm writing. I've created some Entity classes. I want to mock this during unit testing as I believe MS's implementation is good enough to warrant skipping the testing of it. =-}

So, my first guess:

Take the generated ObjectContext-deriving class and generate an interface off of it for the read properties that return ObjectQuery and the Add methods (at this point I'm not worrying about the updating of existing objects, just reading). However, I quickly ran into problems during the testing as I couldn't easily get the ObjectQuery properties working nicely.

I saw The Wayward Weblog's post about doing something similiar to this but with Linq to SQL and it just begs the question, hasn't anyone figured out a better way to mock the Entity framework than this?!

Thanks!

+3  A: 

So I take it there is no answer to this. Unfortunately, after doing lots of googling, I don't think the EF really supports a TDD approach to development, which is an absolute shame. Time to adopt nHibernate, it sounds like.

MBonig
+3  A: 

Wait for EF v2.0 (a year maybe more) or switch to NHibernate. I have choosen the second option (not easy but full TDD support and no database limits).

twk
Agreed, in fact, I'm now using Fluent NHibernate and I'm quite happy with it over EF. A shame though, it's usually easier to sell clients on using MS tech over OS tech.
MBonig
Some people will always be M$ fanboys. Just remind them the majority of webservers are OpenSource. IMHO, OS tech is definitely the way forward. The Big plus with OpenSource is that I can walk through the code if it ever potentially causes an issue. I'm always second guessing or relying on (sometimes spurious) documentation with M$, plus they like to change APIs as if if the previous version never existed. Luckily there are now lots of great OS .net projects. nHibernate is one of them.
gef