Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to put as the Provider for a mocked IQueryable

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? ----------------------------------------+
like image 902
Vaccano Avatar asked Feb 11 '10 17:02

Vaccano


People also ask

What can be mocked with Moq?

You can use Moq to create mock objects that simulate or mimic a real object. Moq can be used to mock both classes and interfaces.

How do you make a mock object in Nunit?

The three key steps to using mock objects for testing are: Use an interface to describe the object. Implement the interface for production code. Implement the interface in a mock object for testing.

What is mock used for C#?

Mocking is a process that allows you to create a mock object that can be used to simulate the behavior of a real object. You can use the mock object to verify that the real object was called with the expected parameters, and to verify that the real object was not called with unexpected parameters.


1 Answers

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.

like image 142
Johannes Rudolph Avatar answered Sep 27 '22 19:09

Johannes Rudolph