C# test file information.
Inheritance: ISourceCodeTestFile
Example #1
0
        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);
            }
        }
Example #2
0
        private static bool Compile(string tempFile)
        {
            var results = CSharpTestFile.Compile(File.ReadAllText(tempFile), true);

            if (results.Errors.Count > 0)
            {
                CompilerError error = null;

                error = TestUtilities.GetCompilerError(results);

                if (error != null)
                {
                    string messageFormat =
                        "Test source code should not produce compiler errors. " +
                        "Error: {0} - {1}, line {2}, column {3} ";
                    Assert.Fail(
                        messageFormat,
                        error.ErrorText,
                        tempFile,
                        error.Line,
                        error.Column);
                }
                return(false);
            }
            return(true);
        }
        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.");
            }
        }
Example #4
0
        /// <summary>
        /// Gets the test file contents.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>The test file contents.</returns>
        private static string GetTestFileContents(string fileName)
        {
            string contents = null;

            using (Stream stream = CSharpTestFile.GetTestFileStream(fileName))
            {
                Assert.IsNotNull(stream, "Test stream could not be retrieved.");

                StreamReader reader = new StreamReader(stream);
                contents = reader.ReadToEnd();
            }

            return(contents);
        }
Example #5
0
        public void TestExpressionPropertyWithGreaterThanSignInBody()
        {
            CSharpTestFile testFile = CSharpTestUtilities.GetExpressionBodyFile();

            using (TextReader reader = testFile.GetReader())
            {
                CSharpParser parser = new CSharpParser();
                ReadOnlyCollection <ICodeElement> elements = parser.Parse(reader);
                var bugfix = elements[2].Children[0].Children[3];
                bugfix.Name.Should().Be("Bugfix");
                bugfix.Children.Should().HaveCount(2, "because there are only 2 properties");
                bugfix.Children[0].ElementType.Should().Be(ElementType.Property);
                bugfix.Children[1].ElementType.Should().Be(ElementType.Property);
                ((PropertyElement)bugfix.Children[1]).ExpressionBodyText.Should().Be("Value > 10");
            }
        }
Example #6
0
 /// <summary>
 /// Compiles source code text to the specified assembly.
 /// </summary>
 /// <param name="text">Text to compile.</param>
 /// <param name="assemblyName">Output assembly name.</param>
 /// <returns>Compiler results.</returns>
 protected override CompilerResults Compile(string text, string assemblyName)
 {
     return(CSharpTestFile.Compile(text, assemblyName));
 }