Beispiel #1
0
        public void AddTransitiveRelations()
        {
            DsiModel dataModel = new DsiModel("Test", Assembly.GetExecutingAssembly());

            IDsiElement element1 = dataModel.AddElement("element1Name", "class", "");

            Assert.IsNotNull(element1);
            IDsiElement element2 = dataModel.AddElement("element2Name", "class", "");

            Assert.IsNotNull(element2);
            IDsiElement element3 = dataModel.AddElement("element3Name", "class", "");

            Assert.IsNotNull(element3);
            IDsiElement element4 = dataModel.AddElement("element4Name", "class", "");

            Assert.IsNotNull(element4);
            IDsiElement element5 = dataModel.AddElement("element5Name", "class", "");

            Assert.IsNotNull(element5);

            dataModel.AddRelation(element1.Name, element2.Name, "", 1, "context");
            dataModel.AddRelation(element2.Name, element3.Name, "", 1, "context");
            dataModel.AddRelation(element3.Name, element4.Name, "", 1, "context");
            dataModel.AddRelation(element4.Name, element5.Name, "", 1, "context");

            Assert.AreEqual(1, dataModel.GetRelationsOfConsumer(element1.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element1.Id, element2.Id));
            Assert.AreEqual(1, dataModel.GetRelationsOfConsumer(element2.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element2.Id, element3.Id));
            Assert.AreEqual(1, dataModel.GetRelationsOfConsumer(element3.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element3.Id, element4.Id));
            Assert.AreEqual(1, dataModel.GetRelationsOfConsumer(element4.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element4.Id, element5.Id));
            Assert.AreEqual(0, dataModel.GetRelationsOfConsumer(element5.Id).Count);

            AddTransitiveRelationsAction transformation = new AddTransitiveRelationsAction(dataModel, true, null);

            transformation.Execute();

            Assert.AreEqual(4, dataModel.GetRelationsOfConsumer(element1.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element1.Id, element2.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element1.Id, element3.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element1.Id, element4.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element1.Id, element5.Id));
            Assert.AreEqual(3, dataModel.GetRelationsOfConsumer(element2.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element2.Id, element3.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element2.Id, element4.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element2.Id, element5.Id));
            Assert.AreEqual(2, dataModel.GetRelationsOfConsumer(element3.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element3.Id, element4.Id));
            Assert.IsTrue(dataModel.DoesRelationExist(element3.Id, element5.Id));
            Assert.AreEqual(1, dataModel.GetRelationsOfConsumer(element4.Id).Count);
            Assert.IsTrue(dataModel.DoesRelationExist(element4.Id, element5.Id));
            Assert.AreEqual(0, dataModel.GetRelationsOfConsumer(element5.Id).Count);
        }
Beispiel #2
0
        public void LoadingAndSavedModelRestoresThePreviousState()
        {
            string filename = "temp.dsi";

            DsiModel dataModel1 = new DsiModel("Test", Assembly.GetExecutingAssembly());

            IDsiElement consumer = dataModel1.AddElement("consumerName", "class", "consumerSource");

            Assert.IsNotNull(consumer);
            IDsiElement provider1 = dataModel1.AddElement("provider1Name", "class", "provider1Source");

            Assert.IsNotNull(provider1);
            IDsiElement provider2 = dataModel1.AddElement("provider2Name", "class", "provider2Source");

            Assert.IsNotNull(provider2);

            dataModel1.AddRelation(consumer.Name, provider1.Name, "relationType2", 2, "context");
            dataModel1.AddRelation(consumer.Name, provider2.Name, "relationType3", 3, "context");

            dataModel1.Save(filename, false, null);

            DsiModel dataModel2 = new DsiModel("Test", Assembly.GetExecutingAssembly());

            dataModel2.Load(filename, null);

            Assert.AreEqual(dataModel1.TotalElementCount, dataModel2.TotalElementCount);
            List <IDsiElement> dataModel1Elements = dataModel1.GetElements().ToList();
            List <IDsiElement> dataModel2Elements = dataModel2.GetElements().ToList();

            for (int elementIndex = 0; elementIndex < dataModel1.TotalElementCount; elementIndex++)
            {
                Assert.AreEqual(dataModel1Elements[elementIndex].Id, dataModel2Elements[elementIndex].Id);
                Assert.AreEqual(dataModel1Elements[elementIndex].Name, dataModel2Elements[elementIndex].Name);
                Assert.AreEqual(dataModel1Elements[elementIndex].Type, dataModel2Elements[elementIndex].Type);
                Assert.AreEqual(dataModel1Elements[elementIndex].Source, dataModel2Elements[elementIndex].Source);
                Assert.AreEqual(dataModel1.GetRelationsOfConsumer(dataModel1Elements[elementIndex].Id).Count, dataModel2.GetRelationsOfConsumer(dataModel1Elements[elementIndex].Id).Count);

                List <IDsiRelation> dataModel1Relations = dataModel1.GetRelationsOfConsumer(dataModel1Elements[elementIndex].Id).ToList();
                List <IDsiRelation> dataModel2Relations = dataModel2.GetRelationsOfConsumer(dataModel2Elements[elementIndex].Id).ToList();

                for (int relationIndex = 0; relationIndex < dataModel1.GetRelationsOfConsumer(dataModel1Elements[elementIndex].Id).Count;
                     relationIndex++)
                {
                    Assert.AreEqual(dataModel1Relations[relationIndex].ConsumerId, dataModel2Relations[relationIndex].ConsumerId);
                    Assert.AreEqual(dataModel1Relations[relationIndex].ProviderId, dataModel2Relations[relationIndex].ProviderId);
                    Assert.AreEqual(dataModel1Relations[relationIndex].Type, dataModel2Relations[relationIndex].Type);
                    Assert.AreEqual(dataModel1Relations[relationIndex].Weight, dataModel2Relations[relationIndex].Weight);
                }
            }
        }
Beispiel #3
0
        public void DoNotMergeWhenImplementationDoesNotDependOnHeaderFileWithSameName()
        {
            DsiModel dataModel = new DsiModel("Test", Assembly.GetExecutingAssembly());

            dataModel.AddElement("namespace1.namespace1.element1Name.cpp", "class", "");
            dataModel.AddElement("namespace3.namespace4.element1Name.h", "class", "");

            Assert.IsNotNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.cpp"));
            Assert.IsNotNull(dataModel.FindElementByName("namespace3.namespace4.element1Name.h"));
            Assert.IsNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.h"));

            MoveHeaderElementsAction transformation = new MoveHeaderElementsAction(dataModel, true, null);

            transformation.Execute();

            Assert.IsNotNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.cpp"));
            Assert.IsNotNull(dataModel.FindElementByName("namespace3.namespace4.element1Name.h"));
            Assert.IsNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.h"));
        }
Beispiel #4
0
        public void DoNotMergeWhenImplementationDependsOnHeaderFileWithOtherName()
        {
            DsiModel dataModel = new DsiModel("Test", Assembly.GetExecutingAssembly());

            IDsiElement elementCpp = dataModel.AddElement("namespace1.namespace1.element1Name.cpp", "class", "");
            IDsiElement elementH   = dataModel.AddElement("namespace3.namespace4.ELEMENT1NAME.h", "class", "");

            dataModel.AddRelation(elementCpp.Name, elementH.Name, "", 1, "context");

            Assert.IsNotNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.cpp"));
            Assert.IsNotNull(dataModel.FindElementByName("namespace3.namespace4.ELEMENT1NAME.h"));
            Assert.IsNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.h"));

            MoveHeaderElementsAction transformation = new MoveHeaderElementsAction(dataModel, true, null);

            transformation.Execute();

            Assert.IsNotNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.cpp"));
            Assert.IsNotNull(dataModel.FindElementByName("namespace3.namespace4.ELEMENT1NAME.h"));
            Assert.IsNull(dataModel.FindElementByName("namespace1.namespace1.element1Name.h"));
        }
Beispiel #5
0
        public void RenameOnlyMatchingElements()
        {
            DsiModel dataModel = new DsiModel("Test", System.Reflection.Assembly.GetExecutingAssembly());

            dataModel.AddElement("element1Name", "class", "element1Source");
            dataModel.AddElement("element2Name", "class", "element2Source");

            IDsiElement element1Before = dataModel.FindElementByName("element1Name");

            Assert.IsNotNull(element1Before);
            IDsiElement element2Before = dataModel.FindElementByName("element2Name");

            Assert.IsNotNull(element2Before);
            IDsiElement element3Before = dataModel.FindElementByName("element3Name");

            Assert.IsNull(element3Before);
            IDsiElement element4Before = dataModel.FindElementByName("element4Name");

            Assert.IsNull(element4Before);

            MoveElementsSettings moveElementsSettings = new MoveElementsSettings
            {
                Enabled = true,
                Rules   = new List <MoveElementRule>
                {
                    new MoveElementRule()
                    {
                        From = "element1Name", To = "element3Name"
                    },
                    new MoveElementRule()
                    {
                        From = "ELEMENT2NAME", To = "element4Name"
                    }
                }
            };

            MoveElementsAction transformation = new MoveElementsAction(dataModel, moveElementsSettings, null);

            transformation.Execute();

            IDsiElement element1After = dataModel.FindElementByName("element1Name");

            Assert.IsNull(element1After);
            IDsiElement element2After = dataModel.FindElementByName("element2Name");

            Assert.IsNotNull(element2After);
            IDsiElement element3After = dataModel.FindElementByName("element3Name");

            Assert.IsNotNull(element3After);
            IDsiElement element4After = dataModel.FindElementByName("element4Name");

            Assert.IsNull(element4After);

            // Element1 renamed
            Assert.AreEqual(element1Before.Id, element3After.Id);
            Assert.AreEqual("element3Name", element3After.Name);
            Assert.AreEqual(element1Before.Type, element3After.Type);
            Assert.AreEqual(element1Before.Source, element3After.Source);

            // Element2 not renamed because replace is case sensitive
            Assert.AreEqual(element2Before.Id, element2After.Id);
            Assert.AreEqual(element2Before.Name, element2After.Name);
            Assert.AreEqual(element2Before.Type, element2After.Type);
            Assert.AreEqual(element2Before.Source, element2After.Source);
        }