Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: WinSCP EventArgs are untestable!

Thanks for your suggestions.
Note that some of your suggestions (interfaces, constructor visibility) have implications on COM interoperability.
I'm reluctant to make changes not to break the interoperability, unless there's greater demand for them.
A9G-Data-Droid

WinSCP EventArgs are untestable!

This problem exists for all of the Event Args in WinSCP.

I have a delegate event handler that I want to unit test. My delegate takes a QueryReceivedEventArgs parameter, as the delegate signature must match the event it is handling. I want to send it various query examples to prove that it can handle various queries.

I went to write a unit test for my delegate and I found that the constructor for QueryReceivedEventArgs is internal, I can't new one up for my test. Maybe I could inherit from this type and then it would be acceptable to the event handler? Nope, it's sealed. Maybe it has an interface we can share so my event handler can instead accept the interface? Nope the inheritance looks like QueryReceivedEventArgs < EventArgs.

If you make something with a private (or internal) constructor that is sealed in C# it becomes untestable.

Solutions:

  1. Make a public interface that can be used to mock your eventargs.
  2. Make the constructor of all event args public.
  3. Unseal the event args classes.