Extension for Ninject aiding testability in Moq, NSubstitute, and FakeItEasy
C#
Clone or download
Latest commit fcf2292 Oct 28, 2017
Permalink
Failed to load latest commit information.
src stylecop Oct 28, 2017
.gitignore prepare for 3.3.0 Oct 8, 2017
CHANGELOG.md 3.3.0 Oct 28, 2017
LICENSE.txt Added license file Feb 18, 2011
Ninject.MockingKernel.sln prepare for 3.3.0 Oct 8, 2017
README.md prepare for 3.3.0 Oct 8, 2017
appveyor.yml Update appveyor.yml Oct 10, 2017

README.md

Ninject.MockingKernel

Build status codecov NuGet Version NuGet Downloads

This extension provides integration between Ninject and Moq/NSubstitute/FakeItEasy, creating a "lightweight" auto-mocking container.

Getting started

In your tests, you should use the MockingKernel instead of the StandardKernel. It adds the following features to Ninject:

  1. The following syntax will bind a service to the mocked object of a Mock<T>.
Bind<IService>().ToMock();

You can add additional interfaces to the mock:

Bind<IService>().ToMock(typeof(IInterface1), typeof(IInterface2));
  1. If you request a service that has no binding, instead of creating an implicit self-binding, the MockingKernel will create an instance of Mock<T> and return the mocked object associated with it.

  2. A Reset() method is available, which clears the Ninject cache of any activated instances, regardless of whether they remain in scope. You can call this method after each test to ensure that instances are reactivated, without having to dispose and re-initialize the kernel each time.

Hat tip to Scott Reynolds for the idea, and to Sean Chambers for dogfooding.

Documentation

https://github.com/ninject/Ninject.MockingKernel/wiki