views:

256

answers:

2

I am creating a base class (or base entity) since all my database tables will have a companyID field.

In my unit tests, I have to make sure the companyID value is correct.

If I am returning a list of objects, all the companyIDs should be the same.

Is there a generic way of me writing a test that will loop through all the values, that I could use across all my objects? (they will all inherit from a base class that will have a companyID property).

+1  A: 

Yes; write a function that will loop through all the objects in a list, cast the objects to the base class, verify the cast was successful, and test that the CompanyID is valid. You may have to write different unit test classes for each way of retrieving the list of objects, but once the list is received, you can call a common function from each of those tests.

McWafflestix
Could I use generics to do this somehow?
Blankman
@blankman: sure, you could use a list<Object> to pass the list of objects...
McWafflestix
+1  A: 

one way would be to implement an interface that has the companyId field, then you return a list of that interface, that way you don't have to worry about what the actual type is

BlackTigerX