示例#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);
        }
示例#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);
                }
            }
        }
示例#3
0
        public void TestAnalyzePhysicalView()
        {
            AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();

            analyzerSettings.ExternalIncludeDirectories.Clear();
            analyzerSettings.ViewMode      = ViewMode.PhysicalView;
            analyzerSettings.InputFilename = Path.Combine(TestData.SolutionDirectory, "DsmSuite.sln");
            analyzerSettings.ExternalIncludeDirectories.Add(new ExternalIncludeDirectory {
                Path = Path.Combine(TestData.TestDataDirectory, "DirExternal"), ResolveAs = "External"
            });
            analyzerSettings.InterfaceIncludeDirectories.Add(Path.Combine(TestData.TestDataDirectory, "DirInterfaces"));
            analyzerSettings.RootDirectory = TestData.SolutionDirectory;

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

            Analyzer.VisualStudio.Analysis.Analyzer analyzer = new Analyzer.VisualStudio.Analysis.Analyzer(dataModel, analyzerSettings, null);
            analyzer.Analyze();

            HashSet <string> elementNames = new HashSet <string>();
            Dictionary <string, HashSet <string> > providerNames = new Dictionary <string, HashSet <string> >();

            foreach (IDsiElement element in dataModel.GetElements())
            {
                elementNames.Add(element.Name);

                foreach (IDsiRelation relation in dataModel.GetRelationsOfConsumer(element.Id))
                {
                    if (!providerNames.ContainsKey(element.Name))
                    {
                        providerNames[element.Name] = new HashSet <string>();
                    }

                    IDsiElement provider = dataModel.FindElementById(relation.ProviderId);
                    providerNames[element.Name].Add(provider.Name);
                }
            }

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA3.h"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.Identical.ClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.Identical.CopyClassA1.cpp"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirClones.NotIdentical.ClassA1.cpp"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirIDL.IInterface1.idl"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface1.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface1_i.c"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.MyTypeLibrary.tlb"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirIDL.IInterface2.idl"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface2.h"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.IInterface2_i.c"));
            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.IdlOutput.DsmSuite.Analyzer.VisualStudio.Test.Data.tlb"));

            Assert.IsTrue(elementNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.targetver.h"));

            Assert.IsTrue(elementNames.Contains("External.External.h"));

            HashSet <string> classA2ProviderNames = providerNames["DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.cpp"];

            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA2.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirB.ClassB1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirC.ClassC1.h"));
            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirD.ClassD1.h"));

            Assert.IsTrue(classA2ProviderNames.Contains("External.External.h"));

            Assert.IsTrue(classA2ProviderNames.Contains("DsmSuite.Analyzer.VisualStudio.Test.Data.DirA.ClassA3.h"));
        }