Recently I've started a project for simulating various neural network applications. To handle the considerable amount of data involved I've implemented a SQL-Server back end using the Entity Framework Model first approach.
Additionally I've grown quite fond of the test driven development (TDD) discipline. However in order to do so I need a mock database to run my tests on. After much searching I found multiple solutions both commercial and open source. At this point it's worth noting that I'm quite the novice when it comes to Database related subjects. Consequently I elected to use the msdn described in memory mock for the EF6 framework as described here.
Pff, now we got the background out of the way, here is my question:
I've created my model and generated the database from it. The code generation of the real interface layer is done by the edmx. To unit test I've followed the above described tutorial and adapted the relevant fields to match my database model,. (which can be found https://i.stack.imgur.com/bN9iG.png, unfortunately I dont have the rep to include the image in the post...).
However I don't need all the data for every test, only some subsets. I would like a situation where i can specify in the setup of the test which tables to load an perhaps the depth of loading the dependencies.
The problem I encountered was that the related data was not loaded along with current DBSet when specifying the related foreign key. For example when setting up the data for the Connection set I would like the entries to link to the related data, in this case elements of the Node set:
var context = new TestContext();
context.NodeSet.Add(new Node { NodeID = 1 });
context.NodeSet.Add(new Node { NodeID = 2 });
context.ConnectionSet.Add(new Connection { ConnID = 1, ToNodeID = 1, FromNodeID = 2 });
var conn = context.ConnectionSet.First();
var fromNode = conn.FromNode;
var toNode = conn.ToNode;
In this example the FromNode property of the specified Connection returns null. The desired situation is that the mock has the ability to relate the ToNodeID key to the relevant object. Furthermore I expect that the order of loading is relevant for resolving the key constraints i.a.w. in order to resolve the FromNode field the corresponding Node must exist.
I am open to all suggestions regarding this specific question but also if any of you know a more constructive way to mock an EF6 model first database design.
Thanks in advance!