public void TestMethodNoClass() { TestGenerator testGenerator = new TestGenerator(); string code = new StreamReader("../../../../TestLibrary/ClassEmpty.cs").ReadToEnd(); List <ResultOfTestGeneration> listResult = testGenerator.GenerateTests(code); Assert.AreEqual(1, listResult.Count); }
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")); }
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")); }
public void TestMethodClass2NameAttributeFile() { TestGenerator testGenerator = new TestGenerator(); string code = new StreamReader("../../../../TestLibrary/Class2.cs").ReadToEnd(); List <ResultOfTestGeneration> listResult = testGenerator.GenerateTests(code); var syntaxTree = CSharpSyntaxTree.ParseText(listResult[0].Code); var classes = syntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>().ToList(); Assert.AreEqual(classes.Count, 1); foreach (var classDeclaration in classes) { Assert.AreEqual("Class2UnitTest", classDeclaration.Identifier.Text); List <string> methodAttributes = classDeclaration.DescendantNodes().OfType <AttributeSyntax>(). Select(attribute => attribute.Name.ToString()).ToList(); Assert.IsTrue(methodAttributes.Contains("TestMethod")); } Assert.AreEqual(listResult[0].Name, "Class2UnitTest"); }
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")); } }