What to put as the Provider for a mocked IQueryable
Asked Answered
H

2

5

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? ----------------------------------------+
Heiney answered 11/2, 2010 at 17:13 Comment(0)
F
7

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.

Freely answered 11/2, 2010 at 17:16 Comment(4)
MolesDelegates.Func<IQueryProvider> provider = new List<User>(); says that List<T> does not convert to MolesDelegates.Func<IQueryProvider>Heiney
MolesDelegates.Func<IQueryProvider> provider = new List<User>().AsQueryable().ProviderFreely
Thanks for the tip. The syntax turned out to be: MolesDelegates.Func<IQueryProvider> provider = () => userLinqList.AsQueryable().Provider;Heiney
yeah, glad you could figure it out. I am on the road atm and SO is terrible on iPhone :-)Freely
E
0

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

Eggcup answered 21/3, 2010 at 3:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.