I have a method which I am testing. Given certain inputs, it should write a failure method to the logger (an ILogger). The interface has several overloads for Log(), as well as some properties (ex. a logging level). I am mocking the logger using FakeItEasy.
What I want to assert is that a call to Log() has happened. However, I don’t care about which specific overload got used. How can I do this?
My ideas:
// Doesn't work, since a different overload (with more parameters) is used.
A.CallTo(() => mockLogger.Log(null)).WithAnyArguments().MustHaveHappened();
// "Works", but if the code were to call something else on the logger
// (ex. change the logging level), this would also pass!
Any.CallTo(mockLogger).MustHaveHappened();
Edit
This can be done using the following syntax:
Original answer
There’s no easy way of doing that, and – correct me if I’m wrong – I don’t think there is in any mocking framework.
That being said there is a – not so easy – way to do it provided in the example below.