Mocking NLog4Net with NSubstitute and capturing parameters passed to log.ErrorFormat

279 views Asked by At

Am trying to rewrite into F# the following C# which mocks up a Log4Net logger with NSubstitute and captures the parameters passed to a Log.ErrorFormat call into the _loggerException string.

string _loggerException = string.Empty;

this.c_logger.When(log => log.ErrorFormat(
    Arg.Any<string>(), Arg.Any<string>()))
    .Do(logger => _loggerException = logger.Arg<string>().ToString());

The following is the F# I have reached

let mutable _loggerException = System.String.Empty

let _logger = Substitute.For<ILog>()

SubstituteExtensions.When(_logger, _logger.WarnFormat(Arg.Any<string>(), Arg.Any<string>())).Do(fun logger -> _loggerException <- logger.Arg<string>())

However I am getting an error on the second parameter to SubstituteExtensions.When - _logger.WarnFormat(Arg.Any<string>(), Arg.Any<string>()) as follows:

This expression was expected to have type Action<ILog> but here has type unit.

Any thoughts on what I am doing wrong?

0

There are 0 answers