RamblingRoss
The blog of Ross Fruen, a .NET consultant NUnit mocks and the Extend method
One of the projects I have been working on uses the nunit.mocks assembly.
Previously this project used release 2.4.7 of NUnit. On upgrading to 2.4.8 some tests started to fail.
It appears that the behaviour of the Expect method has subtly changed. Previously the number of times a mocked method was called was irrelevant. With 2.4.8 it now appears Expect needs to be called for each invocation.
The following code under 2.4.7 would allow LogInformation on ILogger to be called any number of times, but under 2.4.8 would only allow it to be called once.
internal static ILogger GetMockLogger()
{
DynamicMock mockLogger = new DynamicMock(typeof(ILogger));
ILogger logger = (ILogger)mockLogger.MockInstance;
mockLogger.Expect("LogInformation");
return logger;
}
To allow log Information to be called twice the following code would be used:
internal static ILogger GetMockLogger()
{
DynamicMock mockLogger = new DynamicMock(typeof(ILogger));
ILogger logger = (ILogger)mockLogger.MockInstance;
mockLogger.Expect("LogInformation");
mockLogger.Expect("LogInformation");
return logger;
}