Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var generator = new TestsGenerator.TestsGenerator();

            var loadSourceFile = new TransformBlock <string, string>(async path =>
            {
                Console.WriteLine($"Loading file ({path})...");

                using (var reader = new StreamReader(path))
                {
                    return(await reader.ReadToEndAsync());
                }
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MAX_DEGREE_OF_PARALLELISM_READ
            });

            var generateTests = new TransformManyBlock <string, TestClass>(sourceCode =>
            {
                Console.WriteLine("Generating test classes...");

                return(generator.Generate(sourceCode));
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MAX_DEGREE_OF_PARALLELISM_GENERATE
            });

            var saveTestFile = new ActionBlock <TestClass>(async testClass =>
            {
                Console.WriteLine($"Saving {testClass.FileName} to {TESTS_DESTINATION}...");

                using (StreamWriter writer = File.CreateText(TESTS_DESTINATION + testClass.FileName))
                {
                    await writer.WriteAsync(testClass.SourceCode);
                }

                Console.WriteLine($"{testClass.FileName} was successfully saved.");
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MAX_DEGREE_OF_PARALLELISM_WRITE
            });

            var linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            loadSourceFile.LinkTo(generateTests, linkOptions);
            generateTests.LinkTo(saveTestFile, linkOptions);

            FILES_DESTINATIONS.ToList().ForEach(dest => loadSourceFile.Post(dest));

            loadSourceFile.Complete();

            saveTestFile.Completion.Wait();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            DirectoryInfo d = new DirectoryInfo(TestsSourse);

            FileInfo[] Files = d.GetFiles("*.cs");
            FilesPaths = (Files.Select(t => t.FullName).ToArray());

            var generator = new TestsGenerator.TestsGenerator();

            var loadSourceFile = new TransformBlock <string, string>(async path =>
            {
                Console.WriteLine($"Loading file ({path})...");
                using (var reader = new StreamReader(path))
                {
                    return(await reader.ReadToEndAsync());
                }
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MaxDegreeOfParallelismRead
            });

            var generateTests = new TransformManyBlock <string, TestClass>(async sourceCode =>
            {
                Console.WriteLine("Generating test classes...");
                return(await generator.GenerateAsync(sourceCode));
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MaxDegreeOfParallelismGenerate
            });

            var saveTestFile = new ActionBlock <TestClass>(async testClass =>
            {
                Console.WriteLine($"Saving {testClass.FileName} to {TestsDestination}...");
                using (StreamWriter writer = File.CreateText(TestsDestination + testClass.FileName))
                {
                    await writer.WriteAsync(testClass.SourceCode);
                }
                Console.WriteLine($"{testClass.FileName} was successfully saved.");
            }, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MaxDegreeOfParallelismWrite
            });

            var linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            loadSourceFile.LinkTo(generateTests, linkOptions);
            generateTests.LinkTo(saveTestFile, linkOptions);
            FilesPaths.ToList().ForEach(path => loadSourceFile.Post(path));
            loadSourceFile.Complete();
            saveTestFile.Completion.Wait();
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            _fullPath   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            _resultPath = _fullPath + @"\..\..\..\Tests";

            _filePaths = new List <string>
            {
                _fullPath + @"\..\..\..\TestsGenerator\Action\FileWriter.cs",
                _fullPath + @"\..\..\..\TestsGenerator\Action\FileReader.cs",
                _fullPath + @"\..\..\..\TestsGenerator\Generator.cs",
                _fullPath + @"\..\..\..\TestsGenerator\SyntaxProcessor.cs",
                _fullPath + @"\..\..\..\TestsGenerator\TestsGenerator.cs"
            };
            _params         = new Params(_resultPath, 2, 2, 2);
            _testsGenerator = new TestsGenerator.TestsGenerator(_filePaths, _params);
            _asyncWriter    = new FileWriter(_params.OutputDirectoryPath);
        }
Exemplo n.º 4
0
        public void TwoClassInOneFile()
        {
            DaleteFile();
            List <string> filePaths = new List <string>
            {
                _fullPath + @"\..\..\TwoClassInOneFile.cs"
            };

            TestsGenerator.TestsGenerator generator =
                new TestsGenerator.TestsGenerator(filePaths, _params);
            FileWriter asyncWriter = new FileWriter(_params.OutputDirectoryPath);

            int startCountFiles = Directory.GetFiles(_resultPath).Length;

            generator.Generate(asyncWriter).Wait();
            int currentCountFiles = Directory.GetFiles(_resultPath).Length;
            int expectedCount     = startCountFiles + filePaths.Count + 1;

            Assert.AreEqual(expectedCount, currentCountFiles);
            File.Delete(_resultPath + @"\FirstClassTests.cs");
            File.Delete(_resultPath + @"\SecondClassTests.cs");
        }