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

Verify gets confused between the same generic and non-generic signature #750

Merged
merged 3 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Moq/InvocationShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
47 changes: 47 additions & 0 deletions tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,51 @@ public void MatchesDerivedTypesForGenericTypes()
mock.Verify(foo => foo.Call(It.IsAny<IBazParam>()), Times.Exactly(2));
}

[Fact]
public void Should_verify_derived_as_generic_parameters()
{
//Arrange
var mock = new Mock<IBaz>();

//Act
mock.Object.Subscribe<BazParam2>();
mock.Object.Subscribe<BazParam>();
mock.Object.Subscribe<IBazParam>();

//Assert
mock.Verify(foo => foo.Subscribe<IBazParam>(), Times.Exactly(3));
mock.Verify(foo => foo.Subscribe<BazParam>(), Times.Exactly(2));
mock.Verify(foo => foo.Subscribe<BazParam2>(), Times.Once);
}

[Fact]
public void Should_not_verify_nongeneric_when_generic_invoked()
{
//Arrange
var mock = new Mock<IBaz>();

//Act
mock.Object.Subscribe<IBazParam>();

//Assert
mock.Verify(foo => foo.Subscribe<IBazParam>(), Times.Once);
mock.Verify(foo => foo.Subscribe(), Times.Never);
}

[Fact]
public void Should_not_verify_generic_when_nongeneric_invoked()
{
//Arrange
var mock = new Mock<IBaz>();

//Act
mock.Object.Subscribe();

//Assert
mock.Verify(foo => foo.Subscribe<IBazParam>(), Times.Never);
mock.Verify(foo => foo.Subscribe(), Times.Once);
}

[Fact]
public void NullArrayValuesForActualInvocationArePrintedAsNullInMockExeptionMessage()
{
Expand Down Expand Up @@ -1496,6 +1541,8 @@ public interface IBazParam
public interface IBaz
{
void Call<T>(T param) where T:IBazParam;
void Subscribe<T>() where T : IBazParam;
void Subscribe();
}

public class BazParam:IBazParam
Expand Down