public void ExceptionThrowingTest() { TestsGeneratorConfig config = new TestsGeneratorConfig { ReadPaths = new List <string> { "NonExistingFile.cs" } }; Assert.ThrowsException <AggregateException>(() => new TestsGenerator(config).Generate().Wait()); }
public void UsingTests() { string testFilesDirectory = "../../"; string testFilePath = testFilesDirectory + "TestFile.cs"; string testClass1FilePath = testFilesDirectory + "TestClass1Test.cs"; string testClass2FilePath = testFilesDirectory + "TestClass2Test.cs"; TestsGeneratorConfig config = new TestsGeneratorConfig { ReadPaths = new List <string> { "../../SimpleTestFile.cs" }, Writer = new AsyncFileWriter() { Directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) }, ReadThreadCount = 2, WriteThreadCount = 2, processThreadCount = 2 }; new TestsGenerator(config).Generate().Wait(); class1Root = CSharpSyntaxTree.ParseText(File.ReadAllText(testClass1FilePath)).GetCompilationUnitRoot(); class2Root = CSharpSyntaxTree.ParseText(File.ReadAllText(testClass2FilePath)).GetCompilationUnitRoot(); List <string> expected = new List <string> { "Microsoft.VisualStudio.TestTools.UnitTesting", "Moq", "System", "TestClassNamespace.Class1" }; CollectionAssert.IsSubsetOf(expected, class1Root.Usings.Select(x => x.Name.ToString()).ToList()); Assert.AreEqual(1, class2Root.Usings.Where((usingEntry) => usingEntry.Name.ToString() == "TestClassNamespace.Class2").Count()); }
public void TestInit() { string testFilesDirectory = "../../"; string testFilePath = testFilesDirectory + "TestFile.cs"; string testClass1FilePath = testFilesDirectory + "TestClass1Test.cs"; string testClass2FilePath = testFilesDirectory + "TestClass2Test.cs"; TestsGeneratorConfig config = new TestsGeneratorConfig { ReadPaths = new List <string> { testFilePath }, Writer = new AsyncFileWriter() { Directory = testFilesDirectory } }; new TestsGenerator(config).Generate().Wait(); class1Root = CSharpSyntaxTree.ParseText(File.ReadAllText(testClass1FilePath)).GetCompilationUnitRoot(); class2Root = CSharpSyntaxTree.ParseText(File.ReadAllText(testClass2FilePath)).GetCompilationUnitRoot(); }
public TestsGenerator(TestsGeneratorConfig config) { this.config = config ?? throw new ArgumentException("Config shouldn't be null"); }