private static void TestVisibility(string source, string interfaceName, SyntaxKind?expectedVisibility)
        {
            // Assembling some code
            IAssemblyLoader assemblyLoader = new Utils.AsmlDasmlAssemblyLoader(source);

            // Loading the assembly
            IAssemblyProxy assembly = assemblyLoader.Load();

            // Locating the interface
            ITypeInfoProxy interfaceDefinition = assembly.LocateType(interfaceName);

            Assert.IsNotNull(interfaceDefinition);

            // Generating the AST
            var factory    = new InterfaceDeclarationSyntaxFactory(interfaceDefinition);
            var syntaxNode = factory.Create();

            Assert.IsNotNull(syntaxNode, "A node was expected to be built");
            Assert.IsInstanceOfType(syntaxNode, typeof(InterfaceDeclarationSyntax), "Expected an interface declaration node to be built");

            var interfaceDeclarationSyntaxNode = syntaxNode as InterfaceDeclarationSyntax;

            var modifiers = interfaceDeclarationSyntaxNode.Modifiers;

            if (expectedVisibility.HasValue)
            {
                Assert.IsTrue(Utils.CheckModifier(modifiers, expectedVisibility.Value), "Class does not have correct visibility");
                return;
            }

            Assert.AreEqual(0, modifiers.Count(), "Expected no modifier");
        }
        public void NameCorrectlyAcquired()
        {
            // Assembling some code
            IAssemblyLoader assemblyLoader = new Utils.AsmlDasmlAssemblyLoader(@"
                interface IMyInterface {
                }
            ");

            // Loading the assembly
            IAssemblyProxy assembly = assemblyLoader.Load();

            // Locating the interface
            ITypeInfoProxy interfaceDefinition = assembly.LocateType("IMyInterface");

            Assert.IsNotNull(interfaceDefinition);

            // Generating the AST
            var factory    = new InterfaceDeclarationSyntaxFactory(interfaceDefinition);
            var syntaxNode = factory.Create();

            Assert.IsNotNull(syntaxNode, "A node was expected to be built");
            Assert.IsInstanceOfType(syntaxNode, typeof(InterfaceDeclarationSyntax), "Expected an interface declaration node to be built");

            var interfaceDeclarationSyntaxNode = syntaxNode as InterfaceDeclarationSyntax;

            var name = interfaceDeclarationSyntaxNode.Identifier.Text;

            Assert.AreEqual("IMyInterface", name, "Interface name not correctly acquired");
        }
        public void ExtendedInterfacesCorrectlyAcquired()
        {
            // Assembling some code
            IAssemblyLoader assemblyLoader = new Utils.AsmlDasmlAssemblyLoader(@"
                interface MyExtendedInterface1 {
                }
                interface MyExtendedInterface2 {
                }
                interface MyExtendedInterface3 {
                }
                interface MyInterface : MyExtendedInterface1, MyExtendedInterface2, MyExtendedInterface3 {
                }
            ");

            // Loading the assembly
            IAssemblyProxy assembly = assemblyLoader.Load();

            // Locating the class
            ITypeInfoProxy interfaceDefinition = assembly.LocateType("MyInterface");

            Assert.IsNotNull(interfaceDefinition);

            // Generating the AST
            var factory    = new InterfaceDeclarationSyntaxFactory(interfaceDefinition);
            var syntaxNode = factory.Create() as InterfaceDeclarationSyntax;

            Assert.IsNotNull(syntaxNode, "An interface declaration node was expected to be built");

            var baseList = syntaxNode.BaseList.Types;

            Assert.AreEqual(3, baseList.Count, "Expected 3 extended interfaces");

            Action <int, string> ExtendedInterfaceChecker = (index, expectedName) =>
            {
                var baseType           = baseList.ElementAt(index);
                var baseTypeIdentifier = baseType.Type as IdentifierNameSyntax;

                Assert.IsNotNull(baseTypeIdentifier, "Identifier expected");

                var baseTypeName = baseTypeIdentifier.ToString();
                Assert.AreEqual(expectedName, baseTypeName, "Base type full name not correct");
            };

            ExtendedInterfaceChecker(0, "MyExtendedInterface1");
            ExtendedInterfaceChecker(1, "MyExtendedInterface2");
            ExtendedInterfaceChecker(2, "MyExtendedInterface3");
        }
Пример #4
0
        private static void TestExtendedInterfacesNames(string source, string interfaceName, string[] extendedInterfacesFullNames)
        {
            // Assembling some code
            IAssemblyLoader assemblyLoader = new ScriptSharpReflectionUtils.AsmlDasmlAssemblyLoader(source,
                                                                                                    ScriptNamespaceAttributeHelper.AttributeSourceCode);

            // Loading the assembly
            IAssemblyProxy assembly = assemblyLoader.Load();
            ITypeLookup    lookup   = new LinearSearchTypeLookup(assembly);

            // Locating the class
            ITypeInfoProxy interfaceDefinition = assembly.LocateType(interfaceName);

            Assert.IsNotNull(interfaceDefinition);

            // Generating the AST
            var factory    = new InterfaceDeclarationSyntaxFactory(interfaceDefinition, lookup);
            var syntaxNode = factory.Create() as InterfaceDeclarationSyntax;

            Assert.IsNotNull(syntaxNode, "An interface declaration node was expected to be built");

            var baseList = syntaxNode.BaseList.Types;

            Assert.AreEqual(extendedInterfacesFullNames.Length, baseList.Count, $"Expected {extendedInterfacesFullNames.Length} extended interfaces");

            Action <int, string> ExtendedInterfaceChecker = (index, expectedName) =>
            {
                var baseType           = baseList.ElementAt(index);
                var baseTypeIdentifier = baseType.Type as QualifiedNameSyntax;

                Assert.IsNotNull(baseTypeIdentifier, "Qualified name expected");

                var baseTypeName = baseTypeIdentifier.ToString();
                Assert.AreEqual(expectedName, baseTypeName, "Base type full name not correct");
            };

            for (int i = 0; i < extendedInterfacesFullNames.Length; i++)
            {
                ExtendedInterfaceChecker(i, extendedInterfacesFullNames[i]);
            }
        }