A.CallTo(() => ...).MustHaveHappened(2, Times.Exactly) fails for unknown reason after upgrading to netcoreapp3.0
See original GitHub issueAfter updating from netcoreapp2.2 to netcoreapp3.0 we’re having some issues with fake it easy. I don’t know whether or not it’s due to fake it easy or netcoreapp. We’re using fake it easy 5.2.0.
This is what we are trying to test:
ILogger logger = kernel.RebindLogger<IExporter>();
kernel.Get<IExporter>().Export();
A.CallTo(() => logger.Log(LogLevel.Warning, A<EventId>._, A<object>._, A<Exception>._, A<Func<object, Exception, string>>._)).MustHaveHappened(2, Times.Exactly);
We just want to make sure that the logger is called two times with LogLevel.Warning.
The relevant part of the result is shown in the attached file below.
We’re getting the two expected calls. The only difference we can see is:
expected: […]ILogger.Log[System.Object]
[…]
actual: […]ILogger[TXS.Analytics.Export.Interface.IExporter].Log[Microsoft.Extensions.Logging.FormattedLogValues]
[…]
Until we upgraded from netcoreapp2.2 to netcoreapp3.0 this worked perfectly fine.
Maybe someone has an idea or has encountered similar problems?
Many thanks in advance! 😃
Assertion failed for the following call:
Microsoft.Extensions.Logging.ILogger.Log`1[System.Object](logLevel: Warning, eventId: <Ignored>, state: <Ignored>, exception: <Ignored>, formatter: <Ignored>)
Expected to find it twice exactly but didn't find it among the calls:
3: Microsoft.Extensions.Logging.ILogger`1[TXS.Analytics.Export.Interface.IExporter].Log`1[Microsoft.Extensions.Logging.FormattedLogValues](
logLevel: Warning,
eventId: 0,
state: [[{OriginalFormat}, Table/View MICH_GIBT_ES_NICHT does not exist.]],
exception: NULL,
formatter: System.Func`3[Microsoft.Extensions.Logging.FormattedLogValues,System.Exception,System.String])
4: Microsoft.Extensions.Logging.ILogger`1[TXS.Analytics.Export.Interface.IExporter].Log`1[Microsoft.Extensions.Logging.FormattedLogValues](
logLevel: Warning,
eventId: 0,
state: [[{OriginalFormat}, Table/View V_PFANDOBJEKT has not defined a primary key.]],
exception: NULL,
formatter: System.Func`3[Microsoft.Extensions.Logging.FormattedLogValues,System.Exception,System.String])
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
That’s because the method that is called is actually
ILogger.Log<FormattedLogvalues>
. In your test, you passA<object>._
for thestate
argument, soTState
is inferred to beobject
, notFormattedLogValues
. So the calls don’t match, since they use a different generic type argument.Unfortunately,
FormattedLogValues
is internal, so you can’t just use it asTState
… A possible workaround is to check the call like this:It kinda sucks, but I don’t see any better alternative
HI Guys, I have sorted out using object.
I wanted to intercept the log method to log to another place in my tests, with the above code it just works OK 😃