You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
using Moq;using Xunit;publicclassTests{[Fact]publicvoidTest(){varserviceMock=newMock<IService>();
serviceMock.Object.SomeMethod(null);
serviceMock.Verify(x => x.SomeMethod(It.IsAny<string>()), Times.Never);}}publicinterfaceIService{voidSomeMethod(stringstr);}
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<>().
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)
The text was updated successfully, but these errors were encountered: