Hi. I'll try to explain further:
Using the Linq-to-SQL code-generator, I generated CustomerDataContext, which inherits from DataContext.
After dragging the Customer table from my data connections (in the Server explorer), I now have a Customer class. similarly a property was generated in CustomerDataContext, as follows:
public System.Data.Linq.Table<Customer> Customers
{
get
{
return this.GetTable<Customer>();
}
}
Now, I've got (in a different assemby), the code as follows
public IList<Customer> FetchAllCustomers()
{
return db.Customers.Where(c => c.Promoted.HasValue).OrderBy(c => c.Promoted).ToList();
}
What I want to do is to substitute the access to the database, and return a mocked customer list, which I create as a List<Customer> with a few values I add during the test.
The test I wrote is:
ICustomerServicesRepository rep = new CustomerServicesRepository();
List<Customer> mockCats = new List<Customer>();
mockCats.Add(new Customer{ ID = 1, Name = "Fake Cat", Promoted = 1 });
mockCats.Add(new Customer{ ID = 2, Name = "Don't show this Fake Cat", Promoted = 0 });
mockCats.Add(new Customer{ ID = 3, Name = "Another Fake Cat", Promoted = 2 });
MockManager.Init();
MockObject mockDC = MockManager.MockObject(typeof(CustomerServicesDataContext));
mockDC.ExpectGetAlways("Customers", mockCats);
IList<Customer> customers = rep.FetchAllCustomers();
Assert.AreEqual(3, customers.Count);
Unfortunately, I don't get the 3 I generated, but the 6 in the database.
What did I do wrong?
Thanks.