Upload related foreign key data to the mocked EF6 database

I recently started a project to simulate various neural network applications. To handle a significant amount of data, I implemented the back end of SQL-Server using the first Entity Framework Model approach.
In addition, I am very interested in the development discipline related to testing (TDD). However, for this I need a mock database to run my tests. After a long search, I found several solutions, both commercial and open source. At this point, it is worth noting that I'm pretty new when it comes to items related to the database. Therefore, I decided to use msdn, described in the memory layout for the EF6 structure, as described here .

Pff, now we have removed the background, here is my question:

I created my model and created a database from it. Interface level real-time code generation is done using edmx. For unit test I followed the tutorial described above and adapted the appropriate fields according to my database model. (which can be found at http://i.imgur.com/julse1Y.png?1 , unfortunately, I have no reputation to include the image in the message ...).
However, I do not need all the data for each test, only some subsets. I need a situation where I can specify in the test setup which tables to load, possibly the depth of dependency loading.

The problem I ran into was that the related data was not loaded with the current DBSet when specifying the corresponding foreign key. For example, when setting up data for a set of connections, I would like records to bind to related data, in this case Node elements 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 layout has the ability to associate the ToNodeID key with the corresponding object. In addition, I expect the boot order to be important for resolving the ia key constraints, in order to allow the FromNode field, a corresponding Node must exist.

I am open to all suggestions on this particular issue, but also if any of you know a more constructive way to mock the design of the first EF6 database.

!

+3
1

, ID, .

, dbsets, Child Parent, ,

public class Child
{
   public int ID_PARENT { get; set; }
   public virtual Parent Parent { get; set; }
}

mocks

var mockedContext = ... ; // create mocked context with mocked DbSets as
                          // shown in the article you refer to

Child c = new Child();

Parent p = new Parent();
c.Parent = p;  // set up the relation manually

mockedContext.Child.Add( c );
mockedContext.Parent.Add( p );

// property resolving works now as you have set it up in an explicit way
// note that IDs are irrelevant
var children = mockedContext.Child.Where( c => c.Parent != null && c.Parent.Name.StartsWith( "n" ) );
+1

All Articles