Exemple #1
0
        public void TestAnalyze()
        {
            AnalyzerSettings analyzerSettings = new AnalyzerSettings
            {
                LoggingEnabled = true,
                InputFilename  = "example.dot",
            };

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

            Jdeps.Analysis.Analyzer analyzer = new Jdeps.Analysis.Analyzer(model, analyzerSettings, null);
            analyzer.Analyze();

            Assert.AreEqual(5, model.TotalElementCount);

            IDsiElement elementJavaxCryptoCipher = model.FindElementByName("javax.crypto.Cipher");

            Assert.IsNotNull(elementJavaxCryptoCipher);

            IDsiElement elementJavaxCryptoCipherTransform = model.FindElementByName("javax.crypto.Cipher.Transform");

            Assert.IsNotNull(elementJavaxCryptoCipherTransform);

            IDsiElement elementJavaxCryptoSpecRcsParameterSpec = model.FindElementByName("javax.crypto.spec.RC5ParameterSpec");

            Assert.IsNotNull(elementJavaxCryptoSpecRcsParameterSpec);

            IDsiElement elementSunSecurityJcaGetInstance = model.FindElementByName("sun.security.jca.GetInstance");

            Assert.IsNotNull(elementSunSecurityJcaGetInstance);

            IDsiElement elementJavaLangCharSequence = model.FindElementByName("java.lang.CharSequence");

            Assert.IsNotNull(elementJavaLangCharSequence);

            Assert.AreEqual(3, model.ResolvedRelationCount);
            Assert.IsTrue(model.DoesRelationExist(elementJavaxCryptoCipher.Id, elementJavaxCryptoSpecRcsParameterSpec.Id));
            Assert.IsTrue(model.DoesRelationExist(elementJavaxCryptoCipher.Id, elementSunSecurityJcaGetInstance.Id));
            Assert.IsTrue(model.DoesRelationExist(elementJavaxCryptoCipherTransform.Id, elementJavaLangCharSequence.Id));
        }
Exemple #2
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"));
        }
Exemple #3
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"));
        }
Exemple #4
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);
        }
Exemple #5
0
        public void TestAnalyze()
        {
            AnalyzerSettings analyzerSettings = new AnalyzerSettings
            {
                LoggingEnabled    = true,
                AssemblyDirectory = TestData.RootDirectory,
                IgnoredNames      = new List <string>()
            };

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

            DotNet.Analysis.Analyzer analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
            analyzer.Analyze();

            // Main elements
            IDsiElement elementMainClient = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient");

            Assert.IsNotNull(elementMainClient);

            IDsiElement elementMainType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType");

            Assert.IsNotNull(elementMainType);

            IDsiElement elementMainTypeMyDelegate = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType/MyDelegate");

            Assert.IsNotNull(elementMainTypeMyDelegate);

            IDsiElement elementMainTypeAnonymous = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType/<>c");

            Assert.IsNotNull(elementMainTypeAnonymous);

            IDsiElement elementInterfaceA = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.InterfaceA");

            Assert.IsNotNull(elementInterfaceA);

            IDsiElement elementBaseType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.BaseType");

            Assert.IsNotNull(elementBaseType);

            IDsiElement elementNestedType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType/NestedType");

            Assert.IsNotNull(elementNestedType);

            // Fields
            IDsiElement elementFieldType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.FieldType");

            Assert.IsNotNull(elementFieldType);

            IDsiElement elementGenericFieldType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericFieldType`1");

            Assert.IsNotNull(elementGenericFieldType);

            IDsiElement elementGenericFieldTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericFieldTypeParameter");

            Assert.IsNotNull(elementGenericFieldTypeParameter);

            // Properties
            IDsiElement elementPropertyType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.PropertyType");

            Assert.IsNotNull(elementPropertyType);

            IDsiElement elementPropertyEnum = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.PropertyEnum");

            Assert.IsNotNull(elementPropertyEnum);

            IDsiElement elementGenericPropertyType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericPropertyType`1");

            Assert.IsNotNull(elementGenericPropertyType);

            IDsiElement elementGenericPropertyTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericPropertyTypeParameter");

            Assert.IsNotNull(elementGenericPropertyTypeParameter);

            // Method variables
            IDsiElement elementMethodVariableType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MethodVariableType");

            Assert.IsNotNull(elementMethodVariableType);

            // Parameters
            IDsiElement elementParameterEnum = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ParameterEnum");

            Assert.IsNotNull(elementParameterEnum);

            IDsiElement elementParameterType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ParameterType");

            Assert.IsNotNull(elementParameterType);

            IDsiElement elementGenericParameterType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericParameterType`1");

            Assert.IsNotNull(elementGenericParameterType);

            IDsiElement elementGenericParameterTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericParameterTypeParameter");

            Assert.IsNotNull(elementGenericParameterTypeParameter);

            // Return types
            IDsiElement elementReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnType");

            Assert.IsNotNull(elementReturnType);

            IDsiElement elementReturnEnum = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnEnum");

            Assert.IsNotNull(elementReturnEnum);

            IDsiElement elementGenericReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnType`1");

            Assert.IsNotNull(elementGenericReturnType);

            IDsiElement elementGenericReturnTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnTypeParameter");

            Assert.IsNotNull(elementGenericReturnTypeParameter);

            IDsiElement elementDelegateGenericParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.DelegateGenericParameter");

            Assert.IsNotNull(elementDelegateGenericParameter);

            IDsiElement elementEventsArgsGenericParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.EventsArgsGenericParameter");

            Assert.IsNotNull(elementEventsArgsGenericParameter);

            // Main relations
            Assert.IsTrue(model.DoesRelationExist(elementMainClient.Id, elementMainType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainClient.Id, elementEventsArgsGenericParameter.Id));

            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementNestedType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementMainTypeAnonymous.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementMainTypeMyDelegate.Id));

            Assert.IsTrue(model.DoesRelationExist(elementMainTypeAnonymous.Id, elementMainTypeMyDelegate.Id));

            Assert.IsTrue(model.DoesRelationExist(elementMainTypeAnonymous.Id, elementDelegateGenericParameter.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainTypeAnonymous.Id, elementDelegateGenericParameter.Id));

            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementInterfaceA.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementBaseType.Id));

            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementEventsArgsGenericParameter.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementDelegateGenericParameter.Id));

            // Field relations
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementFieldType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericFieldType.Id));

            // Property relations
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementPropertyType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementPropertyEnum.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericPropertyType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericPropertyTypeParameter.Id));

            // Method variable relations
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementMethodVariableType.Id));

            // Parameters type relations
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementParameterEnum.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementParameterType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericParameterType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericParameterTypeParameter.Id));

            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementParameterEnum.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementParameterType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericParameterType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericParameterTypeParameter.Id));

            // Return type relations
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementReturnType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementReturnEnum.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericReturnType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericReturnTypeParameter.Id));

            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementReturnType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementReturnEnum.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericReturnType.Id));
            Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericReturnTypeParameter.Id));
        }