Best way to match multiple signatures and ignore parameters

2 posts, 0 answers
  1. Alec
    Alec avatar
    1 posts
    Member since:
    Jul 2007

    Posted 18 May 2015 Link to this post

    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?

  2. Stefan
    Stefan avatar
    198 posts

    Posted 19 May 2015 Link to this post

    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.

    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
Back to Top