/
NUnitResults.cs
50 lines (40 loc) · 1.45 KB
/
NUnitResults.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
using System.Linq;
using System.Xml;
using NUnit.VisualStudio.TestAdapter.Dump;
namespace NUnit.VisualStudio.TestAdapter.NUnitEngine
{
public class NUnitResults
{
public enum SkipReason
{
NoNUnitTests,
LoadFailure
}
public XmlNode TopNode { get; }
public bool IsRunnable { get; }
public string AsString() => FullTopNode.AsString();
private XmlNode FullTopNode { get; }
public NUnitResults(XmlNode results)
{
FullTopNode = results;
// Currently, this will always be the case but it might change
TopNode = results.Name == "test-run" ? results.FirstChild : results;
// ReSharper disable once StringLiteralTypo
IsRunnable = TopNode.GetAttribute("runstate") == "Runnable";
}
public SkipReason WhatSkipReason()
{
var msgNode = TopNode.SelectSingleNode("properties/property[@name='_SKIPREASON']");
if (msgNode != null &&
new[] { "contains no tests", "Has no TestFixtures" }.Any(msgNode.GetAttribute("value")
.Contains))
return SkipReason.NoNUnitTests;
return SkipReason.LoadFailure;
}
public bool HasNoNUnitTests => WhatSkipReason() == SkipReason.NoNUnitTests;
public XmlNodeList TestCases()
{
return TopNode.SelectNodes("//test-case");
}
}
}