質問

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