Unit test FieldMerging event handler

Hello

How should I unit test a method I’m providing as an event handler for the MailMerge.FieldMerging event?

The issues I face trying to test my method:

  1. FieldMergingEventArgs does not inherit from an interface I can mock.
  2. FieldMergingEventArgs has an internal constructor.
  3. I’ve made some progress refactoring my method to accept a MailMergeContext, but that also does not have an interface I can mock and an internal constructor (which I’ve worked around with reflection).

Even having managed to create an instance of MailMergeContext, I can’t set or mock any of the properties in order to arrange the data I need for my tests.

Hi Bernhard,

I’m afraid you can’t.

The FieldMergingEventArgs and MailMergeContext are not intended to be created by the users and thus they don’t have public constructors.

You should probably consider creating the test in the given context that you have, in other words, test the mail merge execution with the provided customization.

Regards,
Mario

Where should I log a feature request for these classes to have interfaces to allow me to create mocks to test my code?

You can create a new feature request using the following link:
https://support.gemboxsoftware.com/community/2/create-topic
I hope this helps.

1 Like