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

As<TInterface> strange behavior #458

Closed
Belorus opened this issue Sep 28, 2017 · 3 comments
Closed

As<TInterface> strange behavior #458

Belorus opened this issue Sep 28, 2017 · 3 comments
Labels
Milestone

Comments

@Belorus
Copy link

Belorus commented Sep 28, 2017

The following code fails

Mock<IService2> mock = new Mock<TestFriendlyService>().As<IService>();

object o =    ((Mock)mock).Object;
IService2 o2 =       mock .Object;

Assert.True(object.ReferenceEquals(o, o2));

Is that ok ?

@stakx
Copy link
Contributor

stakx commented Sep 28, 2017

That is a bit odd... thanks for taking the time to report this. Have you by chance already identified why this is happening? Otherwise I'll take a look at it later today.

@stakx
Copy link
Contributor

stakx commented Sep 28, 2017

The code paths leading to this unexpected result are a bit convoluted, but it looks like a mock "cast" to a different type via .As<T>() doesn't properly keep track of its underlying type. I'd say that's a bug.

@stakx
Copy link
Contributor

stakx commented Sep 28, 2017

@Belorus, this will be fixed in the next release of Moq (version >4.7.127). Thanks again for reporting it!

@stakx stakx closed this as completed Sep 28, 2017
@stakx stakx added this to the v4.7.vNext milestone Sep 29, 2017
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