-
Notifications
You must be signed in to change notification settings - Fork 758
/
SkipAssertsTests.cs
115 lines (99 loc) · 2.88 KB
/
SkipAssertsTests.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#if XUNIT_SKIP
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.v3;
public class SkipAssertsTests
{
public class Skip : AcceptanceTestV3
{
[Fact]
public void GuardClause()
{
Assert.Throws<ArgumentNullException>("reason", () => Assert.Skip(null!));
}
[Fact]
public async Task AcceptanceTest()
{
var results = await RunAsync(typeof(ClassUnderTest));
var skipResult = Assert.Single(results.OfType<_TestSkipped>());
Assert.Equal("This test was skipped", skipResult.Reason);
}
class ClassUnderTest
{
[Fact]
public void Unconditional()
{
Assert.Skip("This test was skipped");
}
}
}
public class SkipUnless : AcceptanceTestV3
{
[Fact]
public void GuardClause()
{
Assert.Throws<ArgumentNullException>("reason", () => Assert.SkipUnless(true, null!));
}
[Fact]
public async Task AcceptanceTest()
{
var results = await RunAsync(typeof(ClassUnderTest));
var skipResult = Assert.Single(results.OfType<_TestSkipped>());
var skipMethodStarting = Assert.Single(results.OfType<_TestMethodStarting>().Where(s => s.TestMethodUniqueID == skipResult.TestMethodUniqueID));
Assert.Equal("Skipped", skipMethodStarting.TestMethod);
Assert.Equal("This test was skipped", skipResult.Reason);
var passResult = Assert.Single(results.OfType<_TestPassed>());
var passMethodStarting = results.OfType<_TestMethodStarting>().Where(ts => ts.TestMethodUniqueID == passResult.TestMethodUniqueID).Single();
Assert.Equal("Passed", passMethodStarting.TestMethod);
}
class ClassUnderTest
{
[Fact]
public void Skipped()
{
Assert.SkipUnless(false, "This test was skipped");
}
[Fact]
public void Passed()
{
Assert.SkipUnless(true, "This test is not skipped");
}
}
}
public class SkipWhen : AcceptanceTestV3
{
[Fact]
public void GuardClause()
{
Assert.Throws<ArgumentNullException>("reason", () => Assert.SkipWhen(true, null!));
}
[Fact]
public async Task AcceptanceTest()
{
var results = await RunAsync(typeof(ClassUnderTest));
var skipResult = Assert.Single(results.OfType<_TestSkipped>());
var skipMethodStarting = Assert.Single(results.OfType<_TestMethodStarting>().Where(s => s.TestMethodUniqueID == skipResult.TestMethodUniqueID));
Assert.Equal("Skipped", skipMethodStarting.TestMethod);
Assert.Equal("This test was skipped", skipResult.Reason);
var passResult = Assert.Single(results.OfType<_TestPassed>());
var passMethodStarting = results.OfType<_TestMethodStarting>().Where(ts => ts.TestMethodUniqueID == passResult.TestMethodUniqueID).Single();
Assert.Equal("Passed", passMethodStarting.TestMethod);
}
class ClassUnderTest
{
[Fact]
public void Skipped()
{
Assert.SkipWhen(true, "This test was skipped");
}
[Fact]
public void Passed()
{
Assert.SkipWhen(false, "This test is not skipped");
}
}
}
}
#endif