문제

I'm trying to test out a part of my program that resolves instances of types. To do this I created a fake IContainer:

this.container = A.Fake<IContainer>();

However, when I reach this line of code:

container.Resolve<APresenter>();

It's throwing a ComponentNotRegisteredException!

How does the fake IContainer know to even throw that exception? The fake container should simply be a fake of the interface, not of the implementation. What's going on here?

도움이 되었습니까?

해결책

It turns out IContainer.Resolve is an extension method of IContainer. It's not defined in the interface. I tried doing a whole bunch of setup on my Fake IContainer to get the extension method to work, but gave up after about an hour.

The far easier way was to create a Resolver interface and a wrapper around an Autofac IContainer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top