Mocking NLog4Net with NSubstitute and capture options passed to log.ErrorFormat

I'm trying to rewrite in F # the following C # which mocks the Log4Net log with NSubstitute and captures the parameters passed to the Log.ErrorFormat call to the _loggerException line.

string _loggerException = string.Empty;

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

      

Below 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 in the second parameter SubstituteExtensions.When

- _logger.WarnFormat(Arg.Any<string>(), Arg.Any<string>())

like this:

This expression was expected to have a type Action<ILog>

, but there is a type here unit

.

Any thoughts on what I am doing wrong?

+3


source to share





All Articles