Question

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? ----------------------------------------+
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top