public void Sort_simple()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.GetOrSetPrimaryKey(entityTypeA.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.GetOrSetPrimaryKey(entityTypeB.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.GetOrSetPrimaryKey(entityTypeC.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            // B -> A -> C
            entityTypeC.GetOrAddForeignKey(entityTypeA.GetPrimaryKey(), entityTypeC.GetOrAddProperty("P", typeof(int)));
            entityTypeA.GetOrAddForeignKey(entityTypeB.GetPrimaryKey(), entityTypeA.GetOrAddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                new[] { entityTypeB.Name, entityTypeA.Name, entityTypeC.Name },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());
        }
        public void Sort_leafy_cycle()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.GetOrSetPrimaryKey(entityTypeA.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.GetOrSetPrimaryKey(entityTypeB.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.GetOrSetPrimaryKey(entityTypeC.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            // C -> B -> C -> A
            entityTypeB.GetOrAddForeignKey(entityTypeC.GetPrimaryKey(), entityTypeB.GetOrAddProperty("P", typeof(int)));
            entityTypeC.GetOrAddForeignKey(entityTypeB.GetPrimaryKey(), entityTypeC.GetOrAddProperty("P", typeof(int)));
            entityTypeA.GetOrAddForeignKey(entityTypeC.GetPrimaryKey(), entityTypeA.GetOrAddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                Strings.FormatCircularDependency(typeof(C).FullName + " -> " + typeof(B).FullName + " -> " + typeof(C).FullName + " -> " + typeof(A).FullName),
                Assert.Throws <InvalidOperationException>(() => model.TopologicalSort()).Message);
        }