-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathInvalidAssemblyFrameworkDriver.cs
More file actions
95 lines (79 loc) · 2.92 KB
/
Copy pathInvalidAssemblyFrameworkDriver.cs
File metadata and controls
95 lines (79 loc) · 2.92 KB
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
92
93
94
95
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Common;
using NUnit.Engine.Extensibility;
namespace NUnit.Engine.Drivers
{
public sealed class InvalidAssemblyFrameworkDriver : IFrameworkDriver
{
private readonly string _name;
private readonly string _fullname;
private readonly string _message;
private readonly string _type;
private const string RUNSTATE = "NotRunnable";
private const string RESULT = "FAILED";
private const string LABEL = "INVALID";
public InvalidAssemblyFrameworkDriver(string assemblyPath, string id, string message)
{
_name = Escape(Path.GetFileName(assemblyPath));
_fullname = Escape(Path.GetFullPath(assemblyPath));
_message = Escape(message);
_type = PathUtils.IsAssemblyFileType(assemblyPath) ? "Assembly" : "Unknown";
ID = id;
}
public string ID { get; }
public string Load(string assemblyPath, IDictionary<string, object> settings)
{
return GetLoadResult();
}
public int CountTestCases(string filter)
{
return 0;
}
public string Run(ITestEventListener? listener, string filter)
{
return GetRunResult();
}
public void RunAsync(ITestEventListener? listener, string filter)
{
listener?.OnTestEvent(GetRunResult());
}
public string Explore(string filter)
{
return GetLoadResult();
}
public void RequestStop()
{
}
public void ForcedStop()
{
}
private static string Escape(string original)
{
return original
.Replace("&", "&")
.Replace("\"", """)
.Replace("'", "'")
.Replace("<", "<")
.Replace(">", ">");
}
private string GetLoadResult() =>
$"<test-suite type='{_type}' id='{TestID}' name='{_name}' fullname='{_fullname}' testcasecount='0' runstate='{RUNSTATE}'>" +
"<properties>" +
$"<property name='_SKIPREASON' value='{_message}'/>" +
"</properties>" +
"</test-suite>";
private string GetRunResult() =>
$"<test-suite type='{_type}' id='{TestID}' name='{_name}' fullname='{_fullname}' testcasecount='0' runstate='{RUNSTATE}' result='{RESULT}' label='{LABEL}'>" +
"<properties>" +
$"<property name='_SKIPREASON' value='{_message}'/>" +
"</properties>" +
"<reason>" +
$"<message>{_message}</message>" +
"</reason>" +
"</test-suite>";
private string TestID => ID + "-1";
}
}