Skip to content

AutoMock fails creating a mock for a delegate type #48

Description

@olstakh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions