Autofac.Extras.Moq
Autofac.Extras.Moq copied to clipboard
AutoMock fails creating a mock for a delegate type
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