Continuation of unit testing the Metric Dashboard.
Watching for new files
The Dashboard listens to the test result folder for new files. As this is done in another thread, the test must wait for the file to be read and processed in order to verify that the feature works. In the older versions of Typemock there was a VerifyWithTimeout api. Here is a hack to do the same with the lambda API’s. This test is actually an interesting test
- I delete the file before copying just to be sure.
- Here I am faking the current date to be the same as the date of the test – this is so that I get the correct value from CurrentProtection
- Hack to Wait for Load() to be called. In this hack I set an event once the method has been called and then I call the real Load() method.
- Copy file to watched location
- Wait for Load to be called
- Here a short wait is needed for the method to complete.
Wouldn’t it be easier to switch the lines inside the “WhenCalled” expression, so the even gets set after the Load performs? You won’t need the Sleep(100) at the end. Or am I missing something?
Yup, that would be a good way.
It just seems a bit brittle.
I would prefer to do something like:
Wait for delegate that is run on another thread to complete.