+1 vote

Hi,

I need to create a SendMessageResult so I can mock it in my unit tests.
But the class has an internal constructor and no interfaces.

Is there any way to gain access to an instance of it, or is there anyway you can make the constructor protected internal instead?

by (600 points)
reopened by

1 Answer

0 votes

At this point SmtpResponse constructor is not public.

We can make it public along with Status and FromRejected fields.

However we'll not make SmtpResponse constructor public, so you want be able to add elements to error lists (e.g. AllResponses).

Would that help you?

[Edit]
All SMTP Send methods return ISendMessageResult interface now.

by (301k points)
Yes, I noticed that SmtpResponse would also be needed, so that would complicate things, that is why I closed the question.

I ended up creating an ISmtpResponse and ISendMessageResult interfaces, and a wrapper for SendMessageResult implementing it, so I do "new SendMessageResultWrapper(originalResult) and can also mock the result for my tests.

The reason I need to do this, is because I need to interpret the SMTP responses (both code and text) and take some decisions in my class, and I need to unit test those decisions.

If you are willing to make it easier to do that in future versions, you could create those interfaces in Mail.dll directly, so Smtp.Send would return an ISendMessageResult, and it would use arrays of ISmtpResponses. This way we could mock the entire object, just like we do with IMail.

This would be "almost" transparent to existing code, as any use with "var result = Send" would be the same, but "SendMessageResult result = Send" would break... would be something to consider for the sake of testability.
We'll do that. Thanks for the input.
...