This is a migrated thread and some comments may be shown as answers.

Best way to match multiple signatures and ignore parameters

1 Answer 23 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alec
Top achievements
Rank 1
Alec asked on 18 May 2015, 02:24 PM

I'm trying to make a mock that verifies that none of the Error or ErrorFormat calls on the log4net ILog interface were called. Given the number of various signatures this seems a bit annoying. Any better ideas that literally making a match for all 7? The .IgnoreArguments() isn't that helpful given I need to match each signature first before ignoring and putting all nulls causes ambiguous call errors so I have to use Arg.IsAny<> all over.

Signatures I want matched:
void Error(object message);

void Error(object message, Exception exception);

void ErrorFormat(string format, params object[] args);

void ErrorFormat(string format, object arg0);

void ErrorFormat(string format, object arg0, object arg1);

void ErrorFormat(string format, object arg0, object arg1, object arg2);

void ErrorFormat(IFormatProvider provider, string format, params object[] args);

Example of matching:

            Mock.Arrange(() => _Logger.Error(Arg.IsAny<object>())).OccursNever();
            Mock.Arrange(() => _Logger.Error(Arg.IsAny<object>(), Arg.IsAny<Exception>())).OccursNever();
... do I have to do all 7 this way?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 May 2015, 07:45 AM
Hi Alec,

Yes, you have to arrange every method separately. Being able to make large sweeping arrangements has been on our list of wanted features for some time, but no one had asked for it so far, so it never made the cut. I suggest that you post a feature request on our feedback portal so that we may prioritize the feature for one of our future releases.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Alec
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or