WinSCP EventArgs are untestable!

Advertisement

A9G-Data-Droid
A9G-Data-Droid avatar
Joined:
Posts:
5
Location:
Space

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.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,276
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum