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

AutoMock fails creating a mock for a delegate type #48

Open
olstakh opened this issue Sep 25, 2024 · 0 comments
Open

AutoMock fails creating a mock for a delegate type #48

olstakh opened this issue Sep 25, 2024 · 0 comments

Comments

@olstakh
Copy link

olstakh commented Sep 25, 2024

Describe the Bug

Assuming AutoMock should support Mock's functionalities - AutoMock fails to create a mock object for a delegate type

Steps to Reproduce

    public interface MyInterface
    {
        delegate int MyDelegate(int x);
    }

public class ReproTest
{
  [Fact]
  public void Repro()
  {
        var autoMock = AutoMock.GetLoose().Mock<MyInterface.MyDelegate>(); // FAIL, unable to cast exception
        var mock = new Mock<MyInterface.MyDelegate>(); // OK
        mock.Setup(x => x(It.IsAny<int>())).Returns(20); // OK
  }
}

Expected Behavior

Successful creation of an auto mock from a delegate type

Exception with Stack Trace

Unable to cast object of type 'MyDelegate' to type 'Moq.IMocked`1[MyInterface+MyDelegate]'.

Happens in AutoMock.Mock method, when casting to IMocked<T>

var obj = (IMocked<T>)Create<T>(true, parameters);

Dependency Versions

Autofac: 6.1.1.0

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

No branches or pull requests

1 participant