Mocking Kernel
One of the advantages of Dependency Injection is that it improves the testability of code units and makes it even easier. Ninject has introduced Mocking Kernel, which facilitates the injection of mock objects. In this section, we will add a Test project to the Northwind
solution and see how to use Mocking Kernel in order to write our unit tests. It is possible to extend Mocking Kernels for different isolation frameworks, and for some of them including RhinoMocks, Moq and NSubstitute, mocking kernel extensions already exist. In this example, we will use the Moq Mocking Kernel in combination with the NUnit framework to write some unit tests for the Northwind.Wpf
project.
Add a new class library project named Northwind.Wpf.Test
to the Northwind
solution and reference the Northwind.Wpf
and Northwind.Model
projects. Since we are going to use some WPF components in our tests, we also need a reference to PresentationCore
. Now using NuGet install Ninject.MockingKernel.Moq
. It will...