开发者

Testing a (big) collection retrieved from a db

I'm c开发者_JAVA技巧urrently doing integration testing on a database and I have the following sql statement:

var date = DateTime.Parse("01-01-2010 20:30:00");
var result = datacontext.Repository<IObject>().Where(r => r.DateTime > date).First();
Assert.IsFalse(result.Finished);

I need to test if the results retrieved from the statement, where the given date is less then the date of the object, have Finished set to False. I do not know how many results I get back and currently I'm getting the first object of the list and check if that object has Finished set to false. I know testing only the first item of the list is not valid testing, as a solution for that I could iterate through the list and check all items on Finished, but putting logic in a Test is kinda going against the concept of writing 'good' tests.

So my question is:

Does anyone have a good solution of how to properly test the results of this list?


You can go the other way around, check if you have any result in that date range that is finished.

If there is any, then your test should fail.

I can't test any fancier code, so I'll give you a simple way:

int noOfResultsFinished = datacontext.Repository<IObject>()
      .Where(r => r.DateTime > date && r.Finished).Count();

if (noOfResultsFinished > 0)
{
     // fail test
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜