Tuesday, July 5, 2011

Data Access from LD.FunctionalTest

Instead of writing a separate query for each entity in your test class e.g.
       
private List<PremiumEntity> FetchPremiums(
    params int[] policyIds)
{
    LinqMetaData metaData = new LinqMetaData(Adapter);
    var query = (from p in metaData.Premium
        where policyIds.Contains (p.PolicyId)
        select p);
    return query.ToList();
}

there is now a method on LinqMetadata you can use along with a property called MetaData on the TestBase class.The above code can now be replaced by a call inside your test that looks like this:

List<PremiumEntity> partnerPremiums = MetaData.GetEntities<PremiumEntity> ();

Similarly you can get the number of entities in the database by calling

List<PremiumEntity> partnerPremiums = MetaData.GetNumEntities<PremiumEntity> ();

Note that you don't need to get the number of entities in the database at the start and compare them with the number at the end because we always start with a clean database.

No comments:

Post a Comment