views:

98

answers:

2

I am working with Moles and mocking a System.Data.Linq.Table.

I got it constructing fine, but when I use it, it wants IQueryable.Provider to be mocked (moled) as well.

I just want it to use normal Linq To Objects. Any idea what that would be?

Here is the syntax I can use:

MTable<User> userTable = new System.Data.Linq.Moles.MTable<User>();
userTable.Bind(new List<User> { UserObjectHelper.TestUser() });

// this is the line that needs help
MolesDelegates.Func<IQueryProvider> provider = //Insert provider here!
                                                             ^
userTable.ProviderSystemLinqIQueryableget = provider         |
                                                             |
                                                             | 
what can I put here? ----------------------------------------+
+2  A: 

Simplest would be a List<T> which can be used as IQueryable<T> via .AsQueryable().

MolesDelegates.Func<IQueryProvider> provider = () => userLinqList.AsQueryable().Provider;

That's what I use as a in memory database to mock out Linq2Sql. Simple and elegant.

Johannes Rudolph
`MolesDelegates.Func<IQueryProvider> provider = new List<User>();` says that List<T> does not convert to MolesDelegates.Func<IQueryProvider>
Vaccano
`MolesDelegates.Func<IQueryProvider> provider = new List<User>().AsQueryable().Provider`
Johannes Rudolph
Thanks for the tip. The syntax turned out to be: `MolesDelegates.Func<IQueryProvider> provider = () => userLinqList.AsQueryable().Provider;`
Vaccano
yeah, glad you could figure it out. I am on the road atm and SO is terrible on iPhone :-)
Johannes Rudolph
A: 

The simple solution would be to bind the list.AsQueryable() to the table. The IQueryable methods would automatically be rerouted to the list.

Peli