When extracting web service calls into an abstraction so they can easily be tested without being reliant on the web service being online how can I abstract event handlers called automatically by the service? The issue I’m running into is that since the API I’m using (EWS) has every class internaled so I can’t create them. This turns into an issue when unit testing because I can’t say for example, when the event gets fired that it should do x, y and z.
How can I extract these event handlers with my own so I can easily mock them?
You’ll need to wrap the class in your own class supporting an interface. For example if your service usage looks like this:
You’ll create an interface:
And your implementing class:
Then you can create a dummy
ISomeServicevia mocking or your own dummy class, and you use theISomeServiceinstanceSomeServiceWrapperin production.Hope that helps.