-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCADtestRunner.cs
91 lines (74 loc) · 3.44 KB
/
CADtestRunner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
#if CoreConsole
#endif
using System;
using System.Collections.Generic;
using System.IO;
using Autodesk.AutoCAD.Runtime;
using CADTestRunner;
using NUnitLite;
using System.Text;
using System.Diagnostics;
using System.Reflection;
[assembly: CommandClass(typeof (NUnitLiteTestRunner))]
namespace CADTestRunner
{
public class NUnitLiteTestRunner
{
/// <summary> This command runs the NUnit tests in this assembly. </summary>
[CommandMethod("RunCADtests", CommandFlags.Session)]
public void RunCADtests()
{
//string directoryName = Path.GetTempPath(); //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string directoryPlugin = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string directoryReportUnit = Path.Combine(directoryPlugin, @"ReportUnit");
Directory.CreateDirectory(directoryReportUnit);
string fileInputXML = Path.Combine(directoryReportUnit, @"Report-NUnit.xml");
string fileOutputHTML = Path.Combine(directoryReportUnit, @"Report-NUnit.html");
string generatorReportUnit = Path.Combine(directoryPlugin, @"ReportUnit", @"ReportUnit.exe");
string[] nunitArgs = new List<string>
{
// for details of options see https://github.com/nunit/docs/wiki/Console-Command-Line
"--trace=verbose" // Tell me everything
,"--result=" + fileInputXML
// , "--work=" + directoryName // save TestResults.xml to the build folder
// , "--wait" // Wait for input before closing console window (PAUSE). Comment this out for batch operations.
}.ToArray();
new AutoRun().Execute(nunitArgs);
// https://github.com/nunit/nunit/commit/6331e7e694439f8cbf000156f138a3e10370ec40
CreateHTMLReport(fileInputXML, fileOutputHTML, generatorReportUnit);
}
private void CreateHTMLReport(string pFileInputXML, string pFileOutputHTML, string pGeneratorReportUnit)
{
if (!File.Exists(pFileInputXML))
return;
if (File.Exists(pFileOutputHTML))
File.Delete(pFileOutputHTML);
string output = string.Empty;
try
{
using (Process process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = pGeneratorReportUnit;
StringBuilder param = new StringBuilder();
param.AppendFormat(" \"{0}\"", pFileInputXML);
param.AppendFormat(" \"{0}\"", pFileOutputHTML);
process.StartInfo.Arguments = param.ToString();
process.Start();
// read the output to return
// this will stop this execute until AutoCAD exits
StreamReader outputStream = process.StandardOutput;
output = outputStream.ReadToEnd();
outputStream.Close();
}
}
catch (System.Exception ex)
{
output = ex.Message;
}
}
}
}