Beispiel #1
0
        public void SimpleClass()
        {
            var node = (@"
                namespace Root.MyNamespace1 {
                    public class MyClass {
                    }
                }
            ").ExtractASTRoot();

            var namespaces = new NodeLocator(node).LocateAll(typeof(NamespaceDeclarationSyntax), true);

            Assert.AreEqual(1, namespaces.Count(), "Expecting only one namespace at root level");

            var @namespace    = namespaces.First() as NamespaceDeclarationSyntax;
            var namespaceName = @namespace.Name.ToString();

            Assert.AreEqual("Root.MyNamespace1", namespaceName, "Wrong namespace name");

            var classes = new NodeLocator(@namespace).LocateAll(typeof(ClassDeclarationSyntax), true);

            Assert.AreEqual(1, classes.Count(), "Expecting only one class in namespace");

            var @class    = classes.First() as ClassDeclarationSyntax;
            var className = @class.Identifier.Text;

            Assert.AreEqual("MyClass", className, "Wrong class name");
        }
Beispiel #2
0
        private static void TestClassWithScriptNamespaceAttribute(string source, string className, string newNamespaceName)
        {
            var node = (source).ExtractASTRoot();

            var namespaces = new NodeLocator(node).LocateAll(typeof(NamespaceDeclarationSyntax), true);

            Assert.AreEqual(1, namespaces.Count(), "Expecting only one namespace at root level");

            var @namespace    = namespaces.First() as NamespaceDeclarationSyntax;
            var namespaceName = @namespace.Name.ToString();

            Assert.AreEqual(newNamespaceName, namespaceName, "Wrong namespace name");

            var classes = new NodeLocator(@namespace).LocateAll(typeof(ClassDeclarationSyntax), true);

            Assert.AreEqual(1, classes.Count(), "Expecting only one class in namespace");

            var @class = classes.First() as ClassDeclarationSyntax;
            var name   = @class.Identifier.Text;

            Assert.AreEqual(className, name, "Wrong class name");
        }