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

IsAny() not matching where it should? #1020

Closed
jez9999 opened this issue May 19, 2020 · 5 comments
Closed

IsAny() not matching where it should? #1020

jez9999 opened this issue May 19, 2020 · 5 comments

Comments

@jez9999
Copy link

jez9999 commented May 19, 2020

So I've been trying to verify if my .NET Core 3 ILogger mock has been called in my Assert phase, and the following successfully throws if my test method logs an error or a critical:

    _weatherLoggerMock.Verify(logger => logger.Log(
        It.IsIn(new LogLevel[] { LogLevel.Error, LogLevel.Critical }),
        It.IsAny<EventId>(),
        It.IsAny<It.IsAnyType>(),
        It.IsAny<Exception>(),
        It.Is<Func<It.IsAnyType, Exception, string>>((v,t) => true)
    ), Times.Never(), "Logger was called with Error or Critical!");

However, the following doesn't throw:

    _weatherLoggerMock.Verify(logger => logger.Log(
        It.IsIn(new LogLevel[] { LogLevel.Error, LogLevel.Critical }),
        It.IsAny<EventId>(),
        It.IsAny<It.IsAnyType>(),
        It.IsAny<Exception>(),
        It.IsAny<Func<It.IsAnyType, Exception, string>>()
    ), Times.Never(), "Logger was called with Error or Critical!");

Is this correct behaviour? It looks like the two should be semantically identical; in both cases I'm saying that the parameter should match the given type, and match no matter what the value. Why doesn't IsAny match?

@stakx
Copy link
Contributor

stakx commented May 19, 2020

See #919 and the ILogger-related linked there.

@jez9999
Copy link
Author

jez9999 commented May 19, 2020

See #919 and the ILogger-related linked there.

I did read that but I don't quite see how it answers this issue? The solution there can't use IsAny() either.

@stakx
Copy link
Contributor

stakx commented May 19, 2020

Again, very likely because of the nested It.IsAnyType. Have you seen #918 (comment)?

@jez9999
Copy link
Author

jez9999 commented May 20, 2020

Ah ok, I see now.

@stakx
Copy link
Contributor

stakx commented May 21, 2020

I'll close this as a duplicate of #918. If you think that's in error please post here again.

@stakx stakx closed this as completed May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants