Exemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            MSBuildLocator.RegisterDefaults();

            RootCommand rootCommand = Program.GenerateCommands();

            rootCommand.Handler = CommandHandler.Create(async(bool generatePointsFile, bool runTests, DirectoryInfo? projectDir, FileInfo? outputFile) =>
            {
                if (!generatePointsFile && !runTests)
                {
                    Console.WriteLine("You didn't give me a task! Use --help for... help! Leave a like if you found out this to be useful!");

                    return;
                }

                string projectDirectory = projectDir?.FullName ?? Environment.CurrentDirectory;

                ProjectCompiler compiler = new ProjectCompiler();

                ICollection <string> assemblyPaths;

                try
                {
                    assemblyPaths = compiler.CompileTestProjects(projectDirectory);
                }
                catch (CompilationFaultedException exception)
                {
                    Console.WriteLine(exception.Message);

                    Environment.Exit(1);

                    return;
                }

                TestProjectData projectData = new TestProjectData();
                foreach (string assemblyPath in assemblyPaths)
                {
                    projectData.LoadProject(assemblyPath);
                }

                if (generatePointsFile)
                {
                    FileInfo resultsFile = outputFile ?? new FileInfo(Path.Combine(projectDirectory, ".tmc_available_points.json"));

                    await WriteToFile(resultsFile, projectData.Points);
                }

                if (runTests)
                {
                    ProjectTestRunner testRunner = new ProjectTestRunner(projectData);
                    testRunner.RunAssemblies(projectData.Assemblies);

                    FileInfo resultsFile = outputFile ?? new FileInfo(Path.Combine(projectDirectory, ".tmc_test_results.json"));

                    await WriteToFile(resultsFile, testRunner.TestResults);
                }