We use Autofac.Extras.Moq.AutoMock. Now I have a constructor dependency using Lazy <>
public MyService(Lazy<IDependency> myLazyDependency) {...}
to test MyService
, we need to make fun of Lazy<Dependency>
.
I am trying to do this with
[ClassInitialize] public static void Init(TestContext context) { autoMock = AutoMock.GetLoose(); } [TestInitialize] public void MyTestInitialize() { var myDepMock = autoMock.Mock<Lazy<IDependency>>(); // <-- throws exception }
This is the exception returned by the test runner:
Initializing the Tests.MyServiceTests.MyTestInitialize method exception. System.InvalidCastException: System.InvalidCastException: cannot list an object of type 'System.Lazy 1[IDependency]' to type 'Moq.IMocked
1 [System.Lazy`1 [IDependency]]' ..
So how can I pass a Lazy <> mocked object using automock.
source share