Ejemplo n.º 1
0
        //-------------------------------------------------------------------------

        static StrategyEntity()
        {
            // Specify the entities this type of entity can depend on.
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(StrategyEntity));
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(RealisationEntity));
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(GoalEntity));
        }
Ejemplo n.º 2
0
        public void AllowedDependencies()
        {
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            Assert.IsTrue(
                EntityRelationshipManager.GetIsDependencyAllowed(
                    typeof(EntityMocks.EntityMock1),
                    typeof(EntityMocks.EntityMock2)));

            Assert.IsFalse(
                EntityRelationshipManager.GetIsDependencyAllowed(
                    typeof(EntityMocks.EntityMock2),
                    typeof(EntityMocks.EntityMock1)));
        }
Ejemplo n.º 3
0
        public void XmlPersistence()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Add some entities.
            EntityMocks.EntityMock1 mock1   = TestObject.AddEntity <EntityMocks.EntityMock1>();
            EntityMocks.EntityMock2 mock2_1 = TestObject.AddEntity <EntityMocks.EntityMock2>();
            EntityMocks.EntityMock2 mock2_2 = TestObject.AddEntity <EntityMocks.EntityMock2>();

            // Add dependencies.
            mock1.AddDependency(mock2_1);
            mock1.AddDependency(mock2_2);

            // Get as xml.
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement  xml    = xmlDoc.CreateElement("Roadmap");

            TestObject.GetAsXml(xml);

            // Initialise a new roadmap using the xml.
            Roadmap newRoadmap = new Roadmap();

            newRoadmap.InitialiseFromXml(xml);

            // Check the entities are present.
            Entity newMock1   = newRoadmap.GetEntity(mock1.Id);
            Entity newMock2_1 = newRoadmap.GetEntity(mock2_1.Id);
            Entity newMock2_2 = newRoadmap.GetEntity(mock2_2.Id);

            Assert.IsNotNull(newMock1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_2.Title, "Entity not found.");

            // Check the dependencies are present.
            ReadOnlyCollection <Entity> dependencies;

            newMock1.GetDependencies(out dependencies);

            Assert.IsTrue(dependencies.Contains(newMock2_1), "Dependency not found.");
            Assert.IsTrue(dependencies.Contains(newMock2_2), "Dependency not found.");
        }
Ejemplo n.º 4
0
        public void XmlFilePersistence()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Add some entities.
            EntityMocks.EntityMock1 mock1   = TestObject.AddEntity <EntityMocks.EntityMock1>();
            EntityMocks.EntityMock2 mock2_1 = TestObject.AddEntity <EntityMocks.EntityMock2>();
            EntityMocks.EntityMock2 mock2_2 = TestObject.AddEntity <EntityMocks.EntityMock2>();

            // Add dependencies.
            mock1.AddDependency(mock2_1);
            mock1.AddDependency(mock2_2);

            // Write to file.
            Roadmap.WriteToFile("XmlFilePersistence.roadmap", TestObject);

            // Initialise a new roadmap from file.
            Roadmap newRoadmap = Roadmap.InstantiateFromFile("XmlFilePersistence.roadmap");

            // Check the entities are present.
            Entity newMock1   = newRoadmap.GetEntity(mock1.Id);
            Entity newMock2_1 = newRoadmap.GetEntity(mock2_1.Id);
            Entity newMock2_2 = newRoadmap.GetEntity(mock2_2.Id);

            Assert.IsNotNull(newMock1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_2.Title, "Entity not found.");

            // Check the dependencies are present.
            ReadOnlyCollection <Entity> dependencies;

            newMock1.GetDependencies(out dependencies);

            Assert.IsTrue(dependencies.Contains(newMock2_1), "Dependency not found.");
            Assert.IsTrue(dependencies.Contains(newMock2_2), "Dependency not found.");
        }
Ejemplo n.º 5
0
        public void AddDependency()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Create entities.
            EntityMocks.EntityMock1 mock1 = new EntityMocks.EntityMock1(0, TestObject);
            EntityMocks.EntityMock2 mock2 = new EntityMocks.EntityMock2(1, TestObject);

            // Create dependencies between entities.
            bool result = TestObject.AddDependency(mock1, mock2);

            Assert.IsTrue(result, "Failed to add dependency.");

            result = TestObject.AddDependency(mock2, mock1);
            Assert.IsFalse(result, "Added a dependency that should've failed.");

            result = TestObject.AddDependency(mock1, mock1);
            Assert.IsFalse(result, "Added itself as a dependency.");

            // GetDependencies() method.
            ReadOnlyCollection <Entity> dependencies;

            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsTrue(dependencies.Contains(mock2), "Dependency not found.");

            // GetDoesDependencyExist() method.
            Assert.IsTrue(TestObject.GetDoesDependencyExist(mock1, mock2));
            Assert.IsFalse(TestObject.GetDoesDependencyExist(mock2, mock1));

            // GetDependants() method.
            List <Entity> dependants;

            TestObject.GetDependants(mock2, out dependants);

            Assert.IsTrue(dependants.Contains(mock1), "Dependant not found.");
        }
Ejemplo n.º 6
0
        public void RemoveDependency()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Set up entities.
            EntityMocks.EntityMock1 mock1   = new EntityMocks.EntityMock1(0, TestObject);
            EntityMocks.EntityMock2 mock2_1 = new EntityMocks.EntityMock2(1, TestObject);
            EntityMocks.EntityMock2 mock2_2 = new EntityMocks.EntityMock2(2, TestObject);

            // Add some dependencies.
            TestObject.AddDependency(mock1, mock2_1);
            TestObject.AddDependency(mock1, mock2_2);

            // Remove a dependency.
            TestObject.RemoveDependency(mock1, mock2_1);

            // Check it was removed.
            ReadOnlyCollection <Entity> dependencies;

            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsFalse(dependencies.Contains(mock2_1), "Dependency still present.");

            // Check the other dependency is still present.
            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsTrue(dependencies.Contains(mock2_2), "Dependency not found.");

            // Remove the remaining dependency entity.
            TestObject.RemoveEntity(mock2_2);

            // Check the dependency is now removed.
            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsFalse(dependencies.Contains(mock2_2), "Dependency still present.");
        }