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? ----------------------------------------+
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With