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

Improve error message when configuring explicitly implemented interface method #1759

Closed
thomaslevesque opened this issue Apr 8, 2020 · 1 comment · Fixed by #1760
Closed
Assignees
Labels
Milestone

Comments

@thomaslevesque
Copy link
Member

thomaslevesque commented Apr 8, 2020

Given this interface and class:

public interface IFoo
{
    int Bar();
}

public class Foo : IFoo
{
    // Explicitly implemented method
    int IFoo.Bar() => 123;
}

When trying to configure the IFoo.Bar() method on a fake Foo:

var foo = A.Fake<Foo>();
A.CallTo(() => ((IFoo)foo).Bar()).Returns(42);

The following exception is thrown:

FakeConfigurationException:

The current proxy generator can not intercept the method UserQuery+IFoo.Bar() for the following reason:
- Can not create proxy for method Int32 UserQuery.IFoo.Bar() because it or its declaring type is not accessible. Make it public, or internal and mark your assembly with [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] attribute, because assembly LINQPadQuery is not strong-named.


The problem is easy enough to fix: just specify options.Implements<IFoo>() in the fake creation options.

However, the error message is misleading and confusing. It seems to imply that the interface or method is not public, which isn't true, and doesn't point to the actual cause of the problem: the fact that IFoo.Bar() is implemented explicitly and can't be overriden unless Foo explicitly implements IFoo as well.

The message in this scenario should to be improved to something along these lines:

Foo implements IFoo.Bar explicitly; in order to fake IFoo.Bar, the faked Foo must implement IFoo explicitly using options.Implements<IFoo>() in the fake creation options.

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.

3 participants