Beispiel #1
0
        public void TestMethodUsing()
        {
            TestGenerator testGenerator = new TestGenerator();
            string        code          = new StreamReader("../../../../TestLibrary/Class2.cs").ReadToEnd();

            List <ResultOfTestGeneration> listResult  = testGenerator.GenerateTests(code);
            ResultOfTestGeneration        classResult = listResult[0];
            CompilationUnitSyntax         root        = CSharpSyntaxTree.ParseText(classResult.Code).GetCompilationUnitRoot();

            List <UsingDirectiveSyntax> usings = GetUsings(root.DescendantNodes());
            List <string> usingNames           = GetUsingNames(usings);

            Assert.IsTrue(usingNames.Contains("Microsoft.VisualStudio.TestTools.UnitTesting"));
        }
Beispiel #2
0
        public void TestMethodClass2Methods()
        {
            TestGenerator testGenerator = new TestGenerator();
            string        code          = new StreamReader("../../../../TestLibrary/Class2.cs").ReadToEnd();

            List <ResultOfTestGeneration> listResult  = testGenerator.GenerateTests(code);
            ResultOfTestGeneration        classResult = listResult[0];
            CompilationUnitSyntax         root        = CSharpSyntaxTree.ParseText(classResult.Code).GetCompilationUnitRoot();

            List <MethodDeclarationSyntax> publicMethods = GetPublicMethods(root.DescendantNodes());

            Assert.AreEqual(2, publicMethods.Count);
            List <string> methodNames = GetMethodNames(publicMethods);

            Assert.IsTrue(methodNames.Contains("FirstMethodTest"));
            Assert.IsTrue(methodNames.Contains("SecondMethodTest"));
        }
Beispiel #3
0
        public void TestMethodAssertAndAttributes()
        {
            TestGenerator testGenerator = new TestGenerator();
            string        code          = new StreamReader("../../../../TestLibrary/Class3.cs").ReadToEnd();

            List <ResultOfTestGeneration> listResult  = testGenerator.GenerateTests(code);
            ResultOfTestGeneration        classResult = listResult[0];
            CompilationUnitSyntax         root        = CSharpSyntaxTree.ParseText(classResult.Code).GetCompilationUnitRoot();

            List <MethodDeclarationSyntax> publicMethods = GetPublicMethods(root.DescendantNodes());

            Assert.AreEqual(3, publicMethods.Count);
            List <string> methodNames = GetMethodNames(publicMethods);

            foreach (MethodDeclarationSyntax method in publicMethods)
            {
                List <string> identifireNames = method.DescendantNodes().OfType <IdentifierNameSyntax>().
                                                Select(identifire => identifire.Identifier.ToString()).ToList();
                Assert.IsTrue(identifireNames.Contains("Assert"));
                List <string> methodAttributes = method.DescendantNodes().OfType <AttributeSyntax>().
                                                 Select(attribute => attribute.Name.ToString()).ToList();
                Assert.IsTrue(methodAttributes.Contains("TestMethod"));
            }
        }