views:

30

answers:

1

I'm working on a unit test which executes some business logic that will eventually result in a refresh (so execute the same query again) of the data.

Using Dependency Injection (with Castle-Windsor) the unit tests use stub objects, so a static list of entities is returned from the method that gets the data.

So how can I test whether this method is called again?

I abused a date-time field in one of the entities to test the second get (DateTime after refresh != before refresh), but I don't think this is really a good solution.

Can someone offer me an elegant solution for this?

+1  A: 

The question "So how can I test whether this method is called again?" sounds like you really want mocks rather than stubs - you're testing protocol rather than just having a static set of data to be returned. Personally I like the Rhino.Mocks library.

Jon Skeet
Thank you for your answer. But can you please elaborate on how a mock object can help me with this problem? (I don't know anything about Rhino.Mocks)
Gerrie Schenck
Mocking tests your interaction with the dependency, rather than just setting values to be returned. See http://ayende.com/wiki/Rhino+Mocks+Introduction.ashx for an introduction to Rhino.Mocks - for general "what is mocking" questions I'd be doing a search for a good article to start with.
Jon Skeet
(i.e. I don't know any good articles offhand, so I'd be doing a search which you can do just as easily. Sorry not to have any appropriate resources off the top of my head.)
Jon Skeet