-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TState in ILogger.Log<TState> used to be object, now FormattedLogValues #1319
Comments
@helloserve can you show an example of "regular" code that would demonstrate this as a breaking change? Please note that if any types from a |
@Eilon , currently our in-production solutions on .NET Core 2.2 have unit tests that verify as per my first example:
This unit test code breaks by simply upgrading to .NET Core 3.0. We don't use In my 3.0 branch the same line fails, and the exception report from Moq in the test panel shows that the invocation can now only be matched when typing TState as I guess something changed in the extension methods ( Here is a complete sample:
This unit test passes when I reference |
It is very good that logging moved towards more typed solution. I guess, Moq, somehow, should be instructed to match I doubt this is issue of aspnet, more of Moq. And it is good that ""breaking"" changes in major version bump. Seems issue should be closed. |
I agree and I prefer more strictly typed solutions, but then those types should be available to reference and perhaps even extend. I don't exactly understand why -Edit- Perhaps I should elaborate on why I don't understand. In this case I'm dealing with the abstraction |
Readonly struct So question is if Let go deeper. I do not say that I am right, but I feel good about what is going on. Not classes are So seems issues should be closed :) |
No. The stuff about GC is interesting, and makes a lot of sense. The performance impact will obviously be massive compared to dealing with it boxed or as a class. But when you're talking about So having And whether these methods now use In your previous comment you suggested that Moq be made able to somehow match So this leaves us stuck, unable to verify and unable to automate. |
It looks like Moq should support |
I guess I'll go knock on their door, then. Thanks. |
FYI to anyone interested, Moq 4.13 (to be released shortly) will have support for generic type parameter matching. The above _loggerMock.Verify(x => x.Log(LogLevel.Warning, It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))); Note the use of |
The fact that it's not longer possible to assert the calls to |
I agree with @thomaslevesque , just came across a similar issue. IMO it is a breaking change. Please don't just brush this problem off as "well Moq should just get their stuff together". Moq has almost as many nuget downloads as Microsoft.Extensions.Logging. @stakx That doesn't actually work :( |
@davidmilligan - My apologies, I think I made a mistake with the last parameter. As per devlooped/moq#918 (comment), Moq doesn't support "nested" type matchers just yet, so for now you may be more lucky with: -_loggerMock.Verify(x => x.Log(LogLevel.Warning, It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>())));
+_loggerMock.Verify(x => x.Log(LogLevel.Warning, It.IsAny<EventId>(), It.IsAny<It.IsAnyType>(), It.IsAny<Exception>(), (Func<It.IsAnyType, Exception, string>)It.IsAny<object>())))); |
@stakx That worked for me - thanks! |
- Prism now highlights args. - Changes to ILogger.Log<TState> broke some unit tests - dotnet/extensions#1319.
Probably not a bug per se, so perhaps just to clarify my understanding of why this change happened, and to explain how this change is breaking us.
In 2.2 I have an assert that verify my code would log in a specific scenario using Moq:
If I substitute
object
here withFormattedLogValues
(which I can do in 2.2 because it's a public class), Moq throws an exception and tells me that the actual invocation was with TState asobject
.When I switch to 3.0 preview, the above Verify() call no longer works and Moq throws the same exception, except now showing that the actual invocation was with TState as
FormattedLogValues
. Unfortunately this class has now become an internal struct, and I cannot substitute it in place ofobject
in my assert to get my tests working again, e.g. I cannot writeWhat would be a way around this? This is breaking a lot of unit tests for us. Can
FormattedLogValues
be changed back to be public perhaps? I assume that when you use the simple extension methods likeLogWarning()
, this is the TState object that it uses, as opposed to me using theILogger.Log()
directly and providing my own state object. Except that this would involve so much change of existing code.The text was updated successfully, but these errors were encountered: