Ejemplo n.º 1
0
        public static string GenerateReport(DotNet dotnet, List <TestExecutionResult> results)
        {
            var report = new StringBuilder();

            // TODO what more information would be useful to have?

            report.AppendLine("Test Report");
            var name    = typeof(Report).Namespace;
            var version = typeof(Report).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;

            report.AppendLine($"Generated by {name} {version}");
            report.AppendLine("Generated on " + DateTime.Now);
            report.AppendLine();

            report.AppendLine("Tested dotnet at: " + dotnet.DotnetPath);
            var runtimes = dotnet.RuntimeVersions
                           .Select(ver => ver.ToString())
                           .Aggregate((s1, s2) => s1 + ", " + s2);

            report.AppendLine("Found Runtimes: " + runtimes);
            var sdks = dotnet.SdkVersions
                       .Select(ver => ver.ToString())
                       .Aggregate((s1, s2) => s1 + ", " + s2);

            report.AppendLine("Found SDKs: " + sdks);
            report.AppendLine();
            report.AppendLine("dotnet --info:");
            report.AppendLine(dotnet.Exec("--info").StandardOutput.ReadToEnd());
            report.AppendLine();
            report.AppendLine("dotnet --version:");
            report.AppendLine(dotnet.Exec("--version").StandardOutput.ReadToEnd());


            foreach (var result in results)
            {
                report.AppendLine("# Test: " + result.Test.File);
                report.AppendLine("# Compiling: \n" + result.CompileResult.Output);
                if (result.CompileResult.Success)
                {
                    report.AppendLine("# Executing: \n" + result.Output);
                }
                report.AppendLine();
            }

            var total  = results.Count();
            var passed = results.Where(result => result.Success).Count();
            var failed = results.Where(result => !result.Success).Count();

            report.AppendLine();
            report.AppendLine("Total: " + total + ", Passed: " + passed + ", Failed: " + failed);
            report.AppendLine();

            return(report.ToString());
        }
        public static TestExecutionResult ExecuteTest(TestInfo test, DotNet dotnet, TestCompileResult compileResult)
        {
            Directory.SetCurrentDirectory(compileResult.WorkingDirectory.FullName);
            var applicationName = compileResult.WorkingDirectory.Name;
            var configuration   = test.Header.Configuration;
            var targetFramework = test.Header.TargetFramework;

            var result = dotnet.Exec($"bin/{configuration}/{targetFramework}/{applicationName}.dll");
            var output = CreateCommandOutput(result);

            return(new TestExecutionResult(test, (result.ExitCode == 0), compileResult, output));
        }
        public static TestCompileResult CompileTest(DotNet dotnet, DirectoryInfo workingDirectory, TestInfo test)
        {
            var        output = "";
            TestHeader header = test.Header;
            var        configurationCommand = " -c " + header.Configuration;
            var        frameworkCommand     = " -f " + header.TargetFramework;

            Directory.SetCurrentDirectory(workingDirectory.FullName);

            // TODO select the runtime to target

            var result = dotnet.Exec("new console");

            output += CreateCommandOutput(result);

            if (result.ExitCode != 0)
            {
                return(new TestCompileResult
                {
                    Output = output,
                    Success = false,
                    WorkingDirectory = workingDirectory,
                });
            }

            new FileInfo(Path.Combine(workingDirectory.FullName, "Program.cs")).Delete();

            test.File.CopyTo(Path.Combine(workingDirectory.FullName, test.File.Name));

            result  = dotnet.Exec("build" + configurationCommand + frameworkCommand);
            output += CreateCommandOutput(result);

            return(new TestCompileResult
            {
                Output = output,
                Success = (result.ExitCode == 0),
                WorkingDirectory = workingDirectory,
            });
        }