Answered by:
Moq and Microsoft.Extensions.Logging.ILogger unit tests failing after Microsoft.Extensions.Logging.Abstractions update

Question
-
Hello,
Some of my unit tests are failing after updating Microsoft.Extensions.Logging.Abstractions from Version=2.0.0.0 to Version=3.1.1.0.
I have an ILogger mocked as so:
var loggerMock = new Mock<ILogger<BillingEventProcessor>>();
loggerMock.Setup(l => l.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<IReadOnlyList<KeyValuePair<string, object>>>(),
It.IsAny<Exception>(),
It.IsAny<Func<object, Exception, string>>()));And a unit that verifies a call to Log() has been made:
logger.Verify(l => l.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<IReadOnlyList<KeyValuePair<string, object>>>(),
It.IsAny<Exception>(),
It.IsAny<Func<object, Exception, string>>())
);Prior to updating, the IReadOnlyList<KeyValuePair<string, object>> type was of type FormattedLogValues.
In v2, FormattedLogValues was a public class but in v3.1.1, FormattedLogValues is an internal readonly struct. This changes appears to be the source of the test failure.
I've tried using It.IsAny<object> for that 3rd parameter instead of the IReadOnlyList or FormattedLogValues, but I didn't have any luck with that.
Anyone know how I can alter this test code to make the test pass? I can see from debugging info that a call to the Log method is made as expected, I just can't figure out how to set up these mocks correctly with the internal readonly struct parameter.
This is a .NET Core 2.2 project.
- Edited by Dudeman 3000 Thursday, May 7, 2020 11:24 PM
- Moved by Xingyu ZhaoMicrosoft contingent staff Friday, May 8, 2020 7:08 AM
Thursday, May 7, 2020 11:18 PM
Answers
-
- Proposed as answer by Dave PatrickMVP Friday, May 8, 2020 12:13 PM
- Marked as answer by Dave PatrickMVP Friday, May 15, 2020 8:45 PM
Friday, May 8, 2020 7:21 AM -
Also try asking for help over here.
https://stackoverflow.com/questions/tagged/.net-core
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Marked as answer by Dave PatrickMVP Friday, May 15, 2020 8:45 PM
Friday, May 8, 2020 12:14 PM
All replies
-
Hi Dudeman 3000,
Thank you for posting here.
In order to help you find a correct forum to go ask questions, I have moved the thread to Where is the forum for ? forum.
Thank you for your understanding.
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Friday, May 8, 2020 7:07 AM -
- Proposed as answer by Dave PatrickMVP Friday, May 8, 2020 12:13 PM
- Marked as answer by Dave PatrickMVP Friday, May 15, 2020 8:45 PM
Friday, May 8, 2020 7:21 AM -
If your question is more related to C#, then ask here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
- Edited by Guido Franzke Friday, May 8, 2020 7:31 AM
Friday, May 8, 2020 7:31 AM -
Also try asking for help over here.
https://stackoverflow.com/questions/tagged/.net-core
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Marked as answer by Dave PatrickMVP Friday, May 15, 2020 8:45 PM
Friday, May 8, 2020 12:14 PM -
Thanks Dave, I've posted the question here: Stackoverflow postMonday, May 11, 2020 8:38 PM
-
Sounds good, you're welcome.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Monday, May 11, 2020 8:39 PM -
Thanks Guido, I've posted the question here: Vstudio Forum PostMonday, May 11, 2020 8:41 PM