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

Expected invocation on the mock should never have been performed, but was 1 times. when upgrading to the latest moq version 4.16.1 from 4.10.0 #1168

Closed
aniketiitg opened this issue Jun 4, 2021 · 2 comments

Comments

@aniketiitg
Copy link

aniketiitg commented Jun 4, 2021

I faced a similar issue when upgrading to the latest moq version 4.16.1 from 4.10.0

Earlier - the verify() of a method with "It.IsAny<string>()", when invoked with parameter null -> This scenario was considered Negative.
serviceMock.Verify(x => x.SomeMethod(<It.IsAny<string>()), Times.Never)
passes when -
SomeMethod(null)

Now with the current version 4.16.1, passing null, the verify considers it as positive.
SomeMethod(null) ->Expected invocation on the mock should never have been performed, but was 1 times.

@stakx - any idea related to this would help.

Originally posted by @aniketiitg in #1055 (comment)

@aniketiitg aniketiitg changed the title I faced a similar issue when upgrading to the latest moq version 4.16.1 from 4.10.0 Expected invocation on the mock should never have been performed, but was 1 times. when upgrading to the latest moq version 4.16.1 from 4.10.0 Jun 4, 2021
@stakx
Copy link
Contributor

stakx commented Jun 8, 2021

Test code:

using Moq;

using Xunit;

public class Tests
{
    [Fact]
    public void Test()
    {
        var serviceMock = new Mock<IService>();
        serviceMock.Object.SomeMethod(null);
        serviceMock.Verify(x => x.SomeMethod(It.IsAny<string>()), Times.Never);
    }
}

public interface IService
{
    void SomeMethod(string str);
}

Outcome with Moq 4.10.0

Moq.MockException : 
Expected invocation on the mock should never have been performed, but was 1 times: x => x.SomeMethod(It.IsAny<String>())
No setups configured.
    
Performed invocations: 
IService.SomeMethod(null)

Outcome with Moq 4.16.1

Moq.MockException : 
Expected invocation on the mock should never have been performed, but was 1 times: x => x.SomeMethod(It.IsAny<string>())
    
Performed invocations:
    
   Mock<IService:1> (x):
    
      IService.SomeMethod(null)

Conclusion

While the error message format has changed a little, I cannot confirm your claim that there has been a fundamental change in behavior between versions 4.10.0 and 4.16.1 regarding whether or not null matches It.IsAny<>().

What am I missing?

@stakx
Copy link
Contributor

stakx commented Jul 4, 2021

Closing due to missing feedback. We cannot proceed without a repro.

@stakx stakx closed this as completed Jul 4, 2021
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