views:

276

answers:

1

I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks to mock the entity context generated by EEF.

var context = MockRepository.GenerateMock<SomeDBEntities>();
IObjectSet<TxMode> objectSet = new List<TxMode> { mode }.AsObjectSet();
context.Expect(c => c.TxModes).Return(objectSet);

The problem is that c.TxModes is a property of type ObjectSet<TxMode> whereas I am trying to return an IObjectSet<TxMode> and I get the following compile error:

Error 4 The best overloaded method match for 

'Rhino.Mocks.Interfaces.IMethodOptions<System.Data.Objects.ObjectSet
<Data.Entities.TxMode>>.Return(System.Data.Objects.ObjectSet
<Data.Entities.TxMode>)' has some invalid arguments.

The AsObjectSet extension method comes from here.

Any idea how I can get this to compile?

+2  A: 

You cannot do it this. Check out the serie of post from Julie Lerman

  1. Agile Entity Framework 4 Repository: Part 1- Model and POCO Classes
  2. Agile Entity Framework 4 Repository: Part 2- The Repository
  3. Agile EF4 Repository: Part 3 -Fine Tuning the Repository
  4. Agile EF 4 Repositories Part 4: Compiled LINQ Queries
  5. Agile Entity Framework 4 Repository Part 5: IObjectSet and Include

She explains very well how to build the repository pattern with EF4 to let you mock that. There are also T4 Template, but that will let you understand how all that works. Without the adapted T4 Template, it is still quite a lot of work to have it up and running, but I find it a very good exercise. :) I'm in fact implementing it myself right now.

Good luck ;)

Stephane