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

Original mocked type not included after downcasting and Get #943

Closed
pjquirk opened this issue Oct 17, 2019 · 1 comment · Fixed by #945
Closed

Original mocked type not included after downcasting and Get #943

pjquirk opened this issue Oct 17, 2019 · 1 comment · Fixed by #945
Labels
Milestone

Comments

@pjquirk
Copy link

pjquirk commented Oct 17, 2019

Consider this code:

using Moq;

public class Program
{
    public interface B { }
    public interface A : B { } 
    	
    public static void Main() 
    {
        Mock<A> a = new Mock<A>();
	// a.As<A>();  // workaround
        B b = a.Object;
        Mock<B> mockb = Mock.Get(b);
        Mock<A> c = mockb.As<A>();  // throws
    }
}

The line to assign c fails with an InvalidOperationException because it doesn't think the mock that wraps B implements A. Note that uncommenting the 'workaround' line fixes the problem.

The workaround makes me think this is a bug rather than intended behavior.

@stakx stakx added the bug label Oct 17, 2019
@stakx stakx added this to the 4.13.1 milestone Oct 17, 2019
@stakx
Copy link
Contributor

stakx commented Oct 17, 2019

Hi @pjquirk, and thanks for reporting this.

To be honest, I'm not sure whether to classify this as a "bug", or as an "enhancement". But I'm happy to go along with your suggestion that this is a bug.

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

Successfully merging a pull request may close this issue.

2 participants