Wednesday, October 06, 2010
Recently, while i was working with a support issue , i found this interesting piece of test code that i would like to share here. This is actually written by Stefan Lieser (clean code developer from Germany forwarded to me by Jan from Telerik Germany). As the title states, it is to mock a specific event for an expected call.
Now Stefan wants to raise an event from WebClient class of System.Net for a download operation. Therefore, first the WebClient class is mocked during setup.
- public void Setup()
- webClient = Mock.Create<WebClient>();
Next the mocking here takes place in two part. First, DownloadDataCompletedEventArgs is mocked to return an expected data when...