I have a table called Subscriptions. I'd like to redirect any LINQ select from that table to a Moles lambda so that only 3 rows are returned from that table -- basically I want to bypass the call to the database. So far, the code I have looks like this:
// lazy loader is here to handle successive calls to the
// same table (otherwise there's an error)
// CM is a namespace alias
Table<CM.Subscriptions> subsTable = null;
MTheDataContext.AllInstances.SubscriptionsGet = (c) =>
{
if (subsTable == null)
{
subsTable = c.GetTable<CM.Subscriptions>();
subsTable.Attach(new CM.Subscriptions() { SubID = 1,
StatusCode = 1, CustomerID = custID1 });
subsTable.Attach(new CM.Subscriptions() { SubID = 2,
StatusCode = 1, CustomerID = custID2 });
subsTable.Attach(new CM.Subscriptions() { SubID = 3,
StatusCode = 4, CustomerID = custID3 });
// c.Refresh(RefreshMode.KeepCurrentValues, t);
}
return subsTable;
};
Unfortunately it doesn't work. I've got about 1000 rows in the Subscriptions table in the database. When I run some test code that has this redirect in it, I get the 1000 rows from the database instead of the 3 rows that are in the redirect method. Clearly I'm missing something. What can I do to return only these 3 rows whenever any test code selects from the Subscriptions? I've got 3 calls to 3 different tables and they all need to select data that isn't in the db to get this test to work.
Clarification: the call to the redirected method does happen when I do a from sub in dc.Subscriptions ...
select. But the rows returned aren't the rows that are in the redirect.