Ejemplo n.º 1
0
        public void ExceptionThrowingTest()
        {
            TestsGeneratorConfig config = new TestsGeneratorConfig
            {
                ReadPaths = new List <string>
                {
                    "NonExistingFile.cs"
                }
            };

            Assert.ThrowsException <AggregateException>(() => new TestsGenerator(config).Generate().Wait());
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 public TestsGenerator(TestsGeneratorConfig config)
 {
     this.config = config ?? throw new ArgumentException("Config shouldn't be null");
 }