diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e30e2461..248bf6c2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1 #### Fixed * `InvalidOperationException` when specifiying setup on mock with mock containing property of type `Nullable` (@dav1dev, #725) +* `Verify` gets confused between the same generic and non-generic signature (@lepijohnny, #749) ## 4.10.1 (2018-12-03) diff --git a/src/Moq/InvocationShape.cs b/src/Moq/InvocationShape.cs index 5f9681035..7c32ba158 100644 --- a/src/Moq/InvocationShape.cs +++ b/src/Moq/InvocationShape.cs @@ -77,7 +77,7 @@ private bool IsOverride(MethodInfo invocationMethod) return false; } - if (method.IsGenericMethod) + if (method.IsGenericMethod || invocationMethod.IsGenericMethod) { if (!method.GetGenericArguments().CompareTo(invocationMethod.GetGenericArguments(), exact: false)) { diff --git a/tests/Moq.Tests/VerifyFixture.cs b/tests/Moq.Tests/VerifyFixture.cs index 3b1c21578..a525a1af5 100644 --- a/tests/Moq.Tests/VerifyFixture.cs +++ b/tests/Moq.Tests/VerifyFixture.cs @@ -899,6 +899,51 @@ public void MatchesDerivedTypesForGenericTypes() mock.Verify(foo => foo.Call(It.IsAny()), Times.Exactly(2)); } + [Fact] + public void Should_verify_derived_as_generic_parameters() + { + //Arrange + var mock = new Mock(); + + //Act + mock.Object.Subscribe(); + mock.Object.Subscribe(); + mock.Object.Subscribe(); + + //Assert + mock.Verify(foo => foo.Subscribe(), Times.Exactly(3)); + mock.Verify(foo => foo.Subscribe(), Times.Exactly(2)); + mock.Verify(foo => foo.Subscribe(), Times.Once); + } + + [Fact] + public void Should_not_verify_nongeneric_when_generic_invoked() + { + //Arrange + var mock = new Mock(); + + //Act + mock.Object.Subscribe(); + + //Assert + mock.Verify(foo => foo.Subscribe(), Times.Once); + mock.Verify(foo => foo.Subscribe(), Times.Never); + } + + [Fact] + public void Should_not_verify_generic_when_nongeneric_invoked() + { + //Arrange + var mock = new Mock(); + + //Act + mock.Object.Subscribe(); + + //Assert + mock.Verify(foo => foo.Subscribe(), Times.Never); + mock.Verify(foo => foo.Subscribe(), Times.Once); + } + [Fact] public void NullArrayValuesForActualInvocationArePrintedAsNullInMockExeptionMessage() { @@ -1496,6 +1541,8 @@ public interface IBazParam public interface IBaz { void Call(T param) where T:IBazParam; + void Subscribe() where T : IBazParam; + void Subscribe(); } public class BazParam:IBazParam