Closed simongh closed 2 years ago
Code sample showing the behaviour
Thanks @simongh . It is considered as a bug fix. See https://github.com/ninject/Ninject/issues/263.
You need to explicitly bind IEnumerable<IService>
to get your mocked services
The latest release of Ninject (3.3.5) causes a breaking change in the MoqMockingKernel.
For given binding such as:
kernel.Bind<IService>().To<MyService>
Ninject will return an instance ofMyService
whenIService
is requested. If we requestIEnumerable<IService>
Ninject will return a collection containingMyService
In unit tests where we're using MoqMockingKernel, we might set up a mock for
IService
asIf we use the MoqMockingKernel to request
IService
we get a mock instance. If we requestIEnumerable<IService>
we get instead an empty enumerable, not as expected the collection of mocks.This works as expected when 3.3.4 is used.