NArrange CSharp parser implementation.
Inheritance: NArrange.Core.CodeParser
 public void TestAutoPropertyInitializersParseCorrectly()
 {
     CSharpTestFile testFile = CSharpTestUtilities.GetAutoPropertyInitializersFile();
     using (TextReader reader = testFile.GetReader())
     {
         CSharpParser parser = new CSharpParser();
         ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
         elements.Should().HaveCount(1, "because there is only one namespace");
         elements[0].Children.Should().HaveCount(1, "because there is 1 class in the namespace");
         elements[0].Children[0].Children.Should().HaveCount(4, "because there are 4 subclasses in the class");
         var customer1 = elements[0].Children[0].Children[0];
         var customer2 = elements[0].Children[0].Children[1];
         var customer3 = elements[0].Children[0].Children[2];
         var customer4 = elements[0].Children[0].Children[3];
         customer1.Children.Should().HaveCount(2, "because there are only 2 properties");
         customer1.Children[0].ElementType.Should().Be(ElementType.Property);
         customer1.Children[1].ElementType.Should().Be(ElementType.Property);
         customer2.Children.Should().HaveCount(2, "because there are only 2 properties");
         customer2.Children[0].ElementType.Should().Be(ElementType.Property);
         customer2.Children[1].ElementType.Should().Be(ElementType.Property);
         customer3.Children.Should().HaveCount(2, "because there is only 1 property and 1 constructor");
         customer3.Children[0].ElementType.Should().Be(ElementType.Property);
         customer3.Children[1].ElementType.Should().Be(ElementType.Constructor);
         customer4.Children.Should().HaveCount(2, "because there are only 2 properties");
         customer4.Children[0].ElementType.Should().Be(ElementType.Property);
         customer4.Children[1].ElementType.Should().Be(ElementType.Property);
     }
 }
        public void ExpectedBlockCloseTest()
        {
            StringReader reader = new StringReader(
                "namespace SampleNamespace\r\n{");

            CSharpParser parser = new CSharpParser();
            parser.Parse(reader);
        }
        public void ParseClassPartialUnspecifiedAccessTest()
        {
            StringReader reader = new StringReader(
                "partial class Test{}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, typeElement.Access, "Unexpected code access.");
            Assert.IsTrue(typeElement.IsPartial, "Expected a partial class.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
        }
        public void ParseUsingExpectedStatementEnd()
        {
            StringReader reader = new StringReader(
                "using System.Text");

            CSharpParser parser = new CSharpParser();
            parser.Parse(reader);
        }
        public void ParseClassNewConstraintOrderTest()
        {
            StringReader reader = new StringReader(
                "public class Test<T> where T : new(), IDisposable {}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseCommentBlockTest()
        {
            StringReader reader = new StringReader(
                "/*\r\n" +
                " * Block comment here\r\n" +
                " */\r\n");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            CommentElement commentBlockElement = elements[0] as CommentElement;
            Assert.AreEqual(CommentType.Block, commentBlockElement.Type, "Element is not a CommentBlockElement.");

            string[] lines = commentBlockElement.Text.Split(
                new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.AreEqual(3, lines.Length, "An unexpected number of comment lines were parsed.");
            Assert.AreEqual(string.Empty, lines[0], "Unexpected comment line at index 0.");
            Assert.AreEqual(" * Block comment here", lines[1], "Unexpected comment line at index 1.");
            Assert.AreEqual(" ", lines[2], "Unexpected comment line at index 2.");
        }
        public void ParseUsingTest()
        {
            StringReader reader = new StringReader(
                "using System.Text;");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            UsingElement usingElement = elements[0] as UsingElement;
            Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
            Assert.AreEqual("System.Text", usingElement.Name, "Unexpected name.");
            Assert.IsTrue(usingElement.IsMovable, "C# should support moving using directives.");
        }
        public void ExpectedFieldEndOfStatementTest()
        {
            StringReader reader = new StringReader(
                "namespace SampleNamespace\r\n" +
                "{\r\n" +
                "    public class SampleClass\r\n" +
                "    {\r\n" +
                "        private string test =\r\n" +
                "    }\r\n" +
                "}");

            CSharpParser parser = new CSharpParser();
            parser.Parse(reader);
        }
        public void ParseClassUnknownTypeParameterTest()
        {
            StringReader reader = new StringReader(
                "public class Test<T> where S : new() {}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseClassDefinitionTest()
        {
            CSharpParser parser = new CSharpParser();

            CSharpTestFile testFile = CSharpTestUtilities.GetClassDefinitionFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(8, elements.Count, "An unexpected number of elements were parsed.");

                CommentElement commentElement = elements[0] as CommentElement;
                Assert.IsNotNull(commentElement, "Expected a CommentElement.");

                CommentElement commentElement1 = elements[1] as CommentElement;
                Assert.IsNotNull(commentElement1, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 1", commentElement1.Text, "Unexpected comment text.");

                CommentElement commentElement2 = elements[2] as CommentElement;
                Assert.IsNotNull(commentElement2, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 2", commentElement2.Text, "Unexpected comment text.");

                CommentElement commentElement3 = elements[3] as CommentElement;
                Assert.IsNotNull(commentElement3, "Expected a CommentElement.");
                Assert.AreEqual(" This is comment line 3", commentElement3.Text, "Unexpected comment text.");

                UsingElement using1 = elements[4] as UsingElement;
                Assert.IsNotNull(using1, "Expected a UsingElement.");
                Assert.AreEqual("System", using1.Name, "Unexpected using name.");

                UsingElement using2 = elements[5] as UsingElement;
                Assert.IsNotNull(using2, "Expected a UsingElement.");
                Assert.AreEqual("System.Collections.Generic", using2.Name, "Unexpected using name.");

                UsingElement using3 = elements[6] as UsingElement;
                Assert.IsNotNull(using3, "Expected a UsingElement.");
                Assert.AreEqual("System.Text", using3.Name, "Unexpected using name.");

                NamespaceElement namespaceElement = elements[7] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");

                Assert.IsNotNull(namespaceElement.Children, "Namespace Children collection should not be null.");
                Assert.AreEqual(1, namespaceElement.Children.Count, "An unexpected number of namespace child elements were parsed.");

                TypeElement classElement = namespaceElement.Children[0] as TypeElement;
                Assert.IsNotNull(classElement, "Expected a TypeElement.");
                Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");
                Assert.AreEqual(3, classElement.HeaderComments.Count, "An unexpected number of class header comment lines were parsed.");
                foreach (ICommentElement comment in
                    classElement.HeaderComments)
                {
                    Assert.AreEqual(CommentType.XmlLine, comment.Type, "Class header comment should be an XML comment.");
                }
                Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected class code access level.");
            }
        }
        public void ParseClassEmptyParameterConstraintListTest()
        {
            StringReader reader = new StringReader(
                "public class Test<T> where T : {}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseAttributeWithAttributeCharacterTest()
        {
            StringReader reader = new StringReader(
                "[assembly: AssemblyDescription(\"SampleAssembly]\")]");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            AttributeElement attributeElement = elements[0] as AttributeElement;
            Assert.IsNotNull(attributeElement, "Element is not a AttributeElement.");
            Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
            Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
            Assert.AreEqual("\"SampleAssembly]\"", attributeElement.BodyText, "Unexpected attribute text.");
        }
        public void ParseBodyEscapedStringTest()
        {
            StringReader reader = new StringReader(
                "public void DoSomething()\r\n" +
                "{\r\n" +
                "\tstring v = string.Empty;\r\n" +
                "\tv = v.Replace(\"\\\\\\\"\", \"\\\"\"\r\n" +
                "}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "Unexpected number of elements were parsed.");
            MethodElement methodElement = elements[0] as MethodElement;
            Assert.IsNotNull(methodElement);

            Assert.IsTrue(
                methodElement.BodyText.Contains("v = v.Replace(\"\\\\\\\"\", \"\\\"\""),
                "Escaped string line was not found in the member body.");
        }
        public void ParseAttributeListTest()
        {
            StringReader reader = new StringReader(
                "[assembly: AssemblyDescription(\"SampleAssembly\"), ComVisible(false),\tAssemblyConfiguration(\"\"), TestAttribute]");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            AttributeElement attributeElement;

            attributeElement = elements[0] as AttributeElement;
            Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
            Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
            Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
            Assert.AreEqual("\"SampleAssembly\"", attributeElement.BodyText, "Unexpected attribute text.");

            Assert.AreEqual(3, attributeElement.Children.Count, "An unexpected number of child elements were parsed.");

            AttributeElement attributeChildElement = attributeElement.Children[0] as AttributeElement;
            Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
            Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
            Assert.AreEqual("ComVisible", attributeChildElement.Name, "Unexpected attribute name.");
            Assert.AreEqual("false", attributeChildElement.BodyText, "Unexpected attribute text.");

            attributeChildElement = attributeElement.Children[1] as AttributeElement;
            Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
            Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
            Assert.AreEqual("AssemblyConfiguration", attributeChildElement.Name, "Unexpected attribute name.");
            Assert.AreEqual("\"\"", attributeChildElement.BodyText, "Unexpected attribute text.");

            attributeChildElement = attributeElement.Children[2] as AttributeElement;
            Assert.IsNotNull(attributeChildElement, "Element is not an AttributeElement.");
            Assert.AreEqual("assembly", attributeChildElement.Target, "Unexpected attribute target.");
            Assert.AreEqual("TestAttribute", attributeChildElement.Name, "Unexpected attribute name.");
            Assert.IsNull(attributeChildElement.BodyText, "Unexpected attribute text.");
        }
        /// <summary>
        /// Gets the ClassMembers test class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Type code element.</returns>
        private static TypeElement GetMembersTestClass(TextReader reader)
        {
            TypeElement classElement;
            CSharpParser parser = new CSharpParser();

            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(9, elements.Count, "Unexpected number of top-level elements.");

            NamespaceElement namespaceElement = elements[8] as NamespaceElement;
            Assert.IsNotNull(namespaceElement, "Expected a namespace element.");

            Assert.AreEqual(2, namespaceElement.Children.Count, "Unexpected number of namespace elements.");

            UsingElement usingElement = namespaceElement.Children[0] as UsingElement;
            Assert.IsNotNull(usingElement, "Expected a using element.");
            Assert.AreEqual("System.ComponentModel", usingElement.Name, "Unexpected using element name.");

            classElement = namespaceElement.Children[1] as TypeElement;
            Assert.IsNotNull(classElement, "Expected a type element.");
            Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class type.");
            Assert.AreEqual("SampleClass", classElement.Name, "Unexpected class name.");
            Assert.AreEqual(4, classElement.HeaderComments.Count, "Unexpected number of header comments.");

            return classElement;
        }
        public void ParseUTF8Test()
        {
            CSharpParser parser = new CSharpParser();

            CSharpTestFile testFile = CSharpTestUtilities.GetUTF8File();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");

                TypeElement classElement = elements[0] as TypeElement;
                Assert.IsNotNull(classElement, "Expected a class element.");
                Assert.AreEqual("UnicodeClass", classElement.Name, "Unexpected class name.");

                Assert.AreEqual(1, classElement.Children.Count, "Unexpected number of child elements.");
                RegionElement regionElement = classElement.Children[0] as RegionElement;
                Assert.IsNotNull(regionElement, "Element is not a RegionElement.");

                Assert.AreEqual(1, regionElement.Children.Count, "Unexpected number of child elements.");
                FieldElement fieldElement = regionElement.Children[0] as FieldElement;
                Assert.IsNotNull(fieldElement, "Element is not a FieldElement.");
                Assert.AreEqual("val", fieldElement.Name, "Unexpected name.");
                Assert.AreEqual(CodeAccess.Private, fieldElement.Access, "Unexpected code access.");
                Assert.AreEqual("string", fieldElement.Type, "Unexpected member type.");
                Assert.AreEqual(1, fieldElement.HeaderComments.Count, "Unexpected number of header comments.");
            }
        }
        public void ParseClassSimpleTest()
        {
            string[] variations =
                {
                    "public class Test{}",
                    "public class Test{};",
                    "public class Test\r\n{\r\n}\r\n"
                };

            foreach (string variation in variations)
            {
                StringReader reader = new StringReader(variation);

                CSharpParser parser = new CSharpParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
                TypeElement typeElement = elements[0] as TypeElement;
                Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
                Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
                Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
                Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
            }
        }
        public void ParseClassExpectedTypeImplementsTest()
        {
            StringReader reader = new StringReader(
                "public class Test<T> where T {}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseClassUnclosedTypeParameterConstraintTest()
        {
            StringReader reader = new StringReader(
                "public class Test<T> where T : IComparable<T {}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseClassImplementsGenericTest()
        {
            string[] variations = new string[]
            {
                "public class Test : IEnumerable<string>{}",
                "public class Test : IEnumerable <string>{}"
            };

            foreach (string variation in variations)
            {
                StringReader reader = new StringReader(variation);

                CSharpParser parser = new CSharpParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
                TypeElement typeElement = elements[0] as TypeElement;
                Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
                Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
                Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
                Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
                Assert.AreEqual(1, typeElement.Interfaces.Count, "Unexpected number of interface implementations.");
                Assert.AreEqual("IEnumerable<string>", typeElement.Interfaces[0].Name, "Unexpected interface implementation name.");
            }
        }
 public void ParseClassUnhandledElementTest3()
 {
     StringReader reader = new StringReader(
         "public class Test{\r\n{\r\npublic string Test;\r\n}");
     CSharpParser parser = new CSharpParser();
     ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
 }
        public void ParseCommentLineTest()
        {
            StringReader reader = new StringReader(
                "//using System.Text;");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            CommentElement commentElement = elements[0] as CommentElement;
            Assert.IsNotNull(commentElement, "Element is not a CommentElement.");
            Assert.AreEqual(CommentType.Line, commentElement.Type, "Unexpected comment type.");
            Assert.AreEqual("using System.Text;", commentElement.Text, "Unexpected comment text.");
        }
        public void ParseClassUnspecifiedAccessTest()
        {
            StringReader reader = new StringReader(
                "class Test\r\n" +
                "{\r\n" +
                "\tclass Nested{}\r\n" +
                "}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, typeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");

            Assert.AreEqual(1, typeElement.Children.Count, "An unexpected number of child elements were parsed.");
            TypeElement nestedtypeElement = typeElement.Children[0] as TypeElement;
            Assert.IsNotNull(nestedtypeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Nested", nestedtypeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, nestedtypeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, nestedtypeElement.Type, "Unexpected type element type.");
        }
        public void ParseConditionDirectiveElseIfTest()
        {
            StringReader reader = new StringReader(
                "#if DEBUG\r\n" +
                "public TestClass(){}\r\n" +
                "#elif TEST\r\n" +
                "protected TestClass(){}\r\n" +
                "#else\r\n" +
                "private TestClass(){}\r\n" +
                "#endif");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");

            ConditionDirectiveElement conditionElement =
                elements[0] as ConditionDirectiveElement;
            Assert.IsNotNull(conditionElement, "Element is not a ConditionDirectiveElement");
            Assert.AreEqual("DEBUG", conditionElement.ConditionExpression, "Unexpected condition expression.");
            Assert.AreEqual(1, conditionElement.Children.Count, "Unexpected number of child elements.");

            ConstructorElement constructorElement =
                conditionElement.Children[0] as ConstructorElement;
            Assert.IsNotNull(constructorElement, "Element is not a ConstructorElement.");
            Assert.AreEqual("TestClass", constructorElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Public, constructorElement.Access, "Unexpected code access.");
            Assert.AreEqual(string.Empty, constructorElement.Parameters, "Unexpected parameter string.");

            Assert.IsNotNull(conditionElement.ElseCondition, "Expected an Else condition.");
            Assert.AreEqual("TEST", conditionElement.ElseCondition.ConditionExpression, "Unexpected condition expression.");
            Assert.AreEqual(1, conditionElement.ElseCondition.Children.Count, "Unexpected number of child elements.");

            ConstructorElement elseIfConstructorElement =
                conditionElement.ElseCondition.Children[0] as ConstructorElement;
            Assert.IsNotNull(elseIfConstructorElement, "Element is not a ConstructorElement.");
            Assert.AreEqual("TestClass", elseIfConstructorElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Protected, elseIfConstructorElement.Access, "Unexpected code access.");
            Assert.AreEqual(string.Empty, elseIfConstructorElement.Parameters, "Unexpected parameter string.");

            Assert.IsNotNull(conditionElement.ElseCondition.ElseCondition, "Expected an Else condition.");
            Assert.AreEqual(1, conditionElement.ElseCondition.ElseCondition.Children.Count, "Unexpected number of child elements.");

            ConstructorElement elseConstructorElement =
                conditionElement.ElseCondition.ElseCondition.Children[0] as ConstructorElement;
            Assert.IsNotNull(elseConstructorElement, "Element is not a ConstructorElement.");
            Assert.AreEqual("TestClass", elseConstructorElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Private, elseConstructorElement.Access, "Unexpected code access.");
            Assert.AreEqual(string.Empty, elseConstructorElement.Parameters, "Unexpected parameter string.");
        }
        public void ParseCommentedMemberTest()
        {
            StringReader reader = new StringReader(
                "//private void DoSomething()\r\n" +
                "//{\r\n" +
                "//}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(3, elements.Count, "An unexpected number of elements were parsed.");
            Assert.AreEqual("private void DoSomething()", ((ICommentElement)elements[0]).Text, "Unexpected comment text.");
            Assert.AreEqual("{", ((ICommentElement)elements[1]).Text, "Unexpected comment text.");
            Assert.AreEqual("}", ((ICommentElement)elements[2]).Text, "Unexpected comment text.");
        }
        public void ParseUsingRedefineTest()
        {
            StringReader reader = new StringReader(
                "using Redefined = System.Text.Encoder;");
            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            UsingElement usingElement = elements[0] as UsingElement;
            Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
            Assert.AreEqual("Redefined", usingElement.Name);
            Assert.AreEqual("System.Text.Encoder", usingElement.Redefine);
        }
        public void ParseConditionDirectiveAttributeUnhandledTest()
        {
            StringReader reader = new StringReader(
                "#if DEBUG\r\n" +
                "[Obsolete()]\r\n" +
                "#endif");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void ParseClassMissingEndregionTest()
        {
            StringReader reader = new StringReader(
                "public class Test\r\n" +
                "{\r\n" +
                "\t#region Fields\r\n" +
                "}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
        public void TestFixtureSetup()
        {
            CSharpTestFile testFile = CSharpTestUtilities.GetClassMembersFile();
            using (TextReader reader = testFile.GetReader())
            {
                CSharpParser parser = new CSharpParser();
                _testElements = parser.Parse(reader);

                Assert.IsTrue(_testElements.Count > 0, "Test file does not contain any elements.");
            }
        }
        public void ParseClassMissingRegionNameTest()
        {
            StringReader reader = new StringReader(
                "public class Test\r\n" +
                "{\r\n" +
                "\t#region\r\n" +
                "\t#endregion\r\n" +
                "}");

            CSharpParser parser = new CSharpParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            Assert.AreEqual(1, elements[0].Children.Count, "An unexpected number of child elements were parsed.");
            RegionElement regionElement = elements[0].Children[0] as RegionElement;
            Assert.IsNotNull(regionElement, "Expected a region element.");
            Assert.AreEqual(string.Empty, regionElement.Name, "Unexpected region name.");
        }