Closed aniketiitg closed 3 years ago
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);
}
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)
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)
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?
Closing due to missing feedback. We cannot proceed without a repro.
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 https://github.com/moq/moq4/issues/1055#issuecomment-854501616