I am writing some unit tests in my project, and I have a datacontext dependent on a controller containing methods that I would like to test.
I use Ninject for dependency injection and Moq to create my datacontext layout. My DI uses an interface IDataContextthat uses my dbml and is used through the injection process.
In my unit test, I create my datacontext layout as follows:
var mock = new Mock<IDataContext>();
var myController = new MyController(mock.Object);
This throws an exception Object reference not set to an instance of an object.in the second line when executing the datacontexts constructor.
I clearly lack a fundamental element in setting this up, however most of the Moq examples I've seen include some kind of test against a mocking object using Setup().
Am I going to do it right? Should I create a layout for my interface IDataContextor something else?
source
share