Skip to content
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

added ILoggerTests to ensure NSubstitute can be used to test specific ILogger calls happened. #732

Merged
merged 3 commits into from
Sep 3, 2023
Merged

added ILoggerTests to ensure NSubstitute can be used to test specific ILogger calls happened. #732

merged 3 commits into from
Sep 3, 2023

Conversation

zlangner
Copy link
Contributor

#634 talks about wanting to use NSubstitute to validate a call into Microsoft.Extensions.Logging.ILogger. I have the same need and found that the new Arg.AnyType is insufficient to solving this problem.

So I've added a new test class that shows a number of scenarios using LoggerExtensions extension methods from Microsoft.Extensions.Logging.ILogger. The tests include:

  • verify any log message with the same LogLevel happened
  • verify a log message with the same LogLevel and message template happened
  • verify a log message with the same LogLevel, message template, and parameters happened

As you'll see, I had to change how TypesAreAllEquivalent works to handle the Func<TState, Exception?, string> used by ILogger.

@dtchepak
Copy link
Member

dtchepak commented Aug 27, 2023

Thanks a lot @zlangner ! I'll have a good look at this as soon as I get a chance.

@icalvo not sure if this example helps give ideas for the AnyType changes you're looking at?

@icalvo
Copy link
Contributor

icalvo commented Aug 28, 2023

@icalvo not sure if this example helps give ideas for the AnyType changes you're looking at?

I don't think so but it's very good since this was the original use case so it's really nice to have this fixed and the test suite as well.

zlangner and others added 2 commits August 29, 2023 21:21
formatting

Co-authored-by: Adam Stachowicz <saibamenppl@gmail.com>
formatting

Co-authored-by: Adam Stachowicz <saibamenppl@gmail.com>
@dtchepak
Copy link
Member

dtchepak commented Sep 3, 2023

Thanks @zlangner ! Also thanks @Saibamen for the review 👍

@dtchepak dtchepak merged commit 3dd1f75 into nsubstitute:main Sep 3, 2023
@zlangner zlangner deleted the add-support-for-ilogger-extension-methods branch September 3, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants