Unit testing InsertGraph()

Apr 2, 2014 at 9:34 AM
Edited Apr 2, 2014 at 9:35 AM
I'm having trouble unit testing the InsertGraph method. Here's my test method
var container = new Container {
    ContainerId = 1,
    ObjectState = ObjectState.Added,
    Categories = new List<Category>() {
        new Category() {
            CategoryId = 2,
            ObjectState = ObjectState.Added,
            Scenarios = new List<Scenario>() {
                new Scenario() {
                    ScenarioId = 3,
                    ObjectState = ObjectState.Added,

// Act

// Assert
var result = unitOfWork.Repository<Container>().Find(1);
Assert.IsNotNull(result, "First result");

var result2 = unitOfWork.Repository<Category>().Find(2);
Assert.IsNotNull(result2, "Second result");

var result3 = unitOfWork.Repository<Scenario>().Find(3);
Assert.IsNotNull(result3, "Third result");
The second and third results fail. However the first result is the full graph, contains the child entities as well.
However when i check the contents of the FakeContext when debugging i can see that neither the category or the scenario are in it.

Is there anything I'm missing? Im using the latest version of the repository and I've checked and my fake context and sets are the same as in the Northwind example that is provided.
Apr 7, 2014 at 2:09 AM
Please use Integration Tests (which sets up test database) for this, the FakeDbContext is simply backed with an ObservableCollection, there is no "real" database persistence happening, FakeDbContext is made for Unit Test to test business logic rather than testing actual database persistence.

We are planning to either refactor the Unit Test project to be full Integration Test, or pull them out since we are coming to realize what we put out there is a bit confusing.
Marked as answer by lelong37 on 4/6/2014 at 6:09 PM
Jun 12, 2015 at 10:38 PM
I would much rather you continue to support your current test and then perhaps expand with more test. Not having them would make learning the framework very hard for a newbie... ;)