Hi Holt,
You can use the method WillReturnCollectionValuesOf() to have Isolator return a list of values as your test data:
Isolate.WhenCalled(() => fakeDataContext.CAD_CatalogProducts)
.WillReturnCollectionValuesOf(GetFakeCanadianProducts());
However, in order to query this data via LINQ, it must be converted to IQueryable<T>. You can use the .ToQueryable() extension method to do this.
The following test shows how to fill a Table of Products with fake test data:
[Test, Isolated]
public void FakeDataContext_ReturnsFakeProducts()
{
var fakeDataContext = Isolate.Fake.Instance<ProductsDataContext>();
Isolate.WhenCalled(() => fakeDataContext.CAD_CatalogProducts)
.WillReturnCollectionValuesOf(GetFakeCanadianProducts());
var products = from p in fakeDataContext.CAD_CatalogProducts
where p.ListPrice > 200 && p.ListPrice < 1000
select p;
Assert.AreEqual(1, products.Count());
}
private IQueryable<CAD_CatalogProduct> GetFakeCanadianProducts()
{
return new List<CAD_CatalogProduct>
{
new CAD_CatalogProduct { ProductID = 1, VariantID = 10, ListPrice = 500 },
new CAD_CatalogProduct { ProductID = 2, VariantID = 20, ListPrice = 1000 }
}.AsQueryable();
}
Please let me know if this helps you out, or if there's anything else I could help you with.
Regards,
Igal,
Typemock Support