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
I went to write a unit test for my delegate and I found that the constructor for
If you make something with a private (or internal) constructor that is sealed in C# it becomes untestable.
Solutions:
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:
- Make a public interface that can be used to mock your eventargs.
- Make the constructor of all event args public.
- Unseal the event args classes.