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

Possibly undocumented breaking change in 4.2.1408.0511 #315

Closed
madelson opened this issue Jan 4, 2017 · 2 comments
Closed

Possibly undocumented breaking change in 4.2.1408.0511 #315

madelson opened this issue Jan 4, 2017 · 2 comments
Labels

Comments

@madelson
Copy link

madelson commented Jan 4, 2017

I recently updated a project from Moq 4.0.10827 to the current version (4.5.29). This caused some tests to fail. I eventually tracked down the issue to the fact that a non-virtual method that implements an interface now seems to be treated as mockable when called through the interface. From what I can tell, this behavior began in version 4.2.1408.0511. Was this change intentional? Is it documented somewhere? I didn't see anything about it in the 4.2 release notes.

Here's the code to reproduce:

void Main()
{
	var m = new Mock<Foo>();
	Console.WriteLine(m.Object.GetValue()); // 10
	Console.WriteLine(((IFoo)m.Object).GetValue()); // 10 in older versions, 0 in newer versions
}

// Define other methods and classes here
public class Foo : IFoo
{
	public int GetValue() => 10;
}

public interface IFoo
{
	int GetValue();
}

I'm not really sure whether I consider the new behavior better or worse. It's definitely a bit strange to have the same method returning a different value when called through the interface when there's no explicit implementation happening in the code. On the other hand, I could see how this could enable some helpful scenarios, and the issue can always be worked around by setting CallBase to true. Assuming it is intentional and desired, maybe we could add something to the release notes to call this out?

@stakx
Copy link
Contributor

stakx commented Jun 20, 2017

Fixed in Moq 4.7.58.

@stakx stakx closed this as completed Jun 20, 2017
@madelson
Copy link
Author

Thanks @stakx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants