Hey everyone,
I'm writing some unit tests in my project and I have a datacontext dependancy on the controller containing the methods I'd like to test.
I'm using Ninject to inject the dependancy and Moq to create my mock datacontext. My DI makes use of an interface IDataContext
which my dbml impliments and is used through out the injection process.
In my unit test I'm creating my mock datacontext as follows:
var mock = new Mock<IDataContext>();
var myController = new MyController(mock.Object);
This throws a Object reference not set to an instance of an object.
exception on the second line whilst executing the datacontexts constructor.
I'm clearly missing a fundamental piece in setting this up however most of the Moq examples I've seen involve some kind of test against the mocked object using Setup()
.
Am I going about this the right way? Should I be creating a mock of my IDataContext
interface or something else?
Cheers for any tips or advice.