-
-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathGitHubReporterTests.cs
More file actions
98 lines (79 loc) · 3.18 KB
/
GitHubReporterTests.cs
File metadata and controls
98 lines (79 loc) · 3.18 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
96
97
98
using Shouldly;
using TUnit.Engine.Reporters;
namespace TUnit.Engine.Tests;
[NotInParallel]
public class GitHubReporterTests
{
[After(Test)]
public void CleanupAfterTest()
{
// Reset all environment variables
Environment.SetEnvironmentVariable("TUNIT_DISABLE_GITHUB_REPORTER", null);
Environment.SetEnvironmentVariable("DISABLE_GITHUB_REPORTER", null);
Environment.SetEnvironmentVariable("TUNIT_GITHUB_REPORTER_STYLE", null);
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", null);
Environment.SetEnvironmentVariable("GITHUB_STEP_SUMMARY", null);
}
[Test]
public async Task IsEnabledAsync_Should_Return_False_When_TUNIT_DISABLE_GITHUB_REPORTER_Is_Set()
{
// Arrange
Environment.SetEnvironmentVariable("TUNIT_DISABLE_GITHUB_REPORTER", "true");
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", "true");
Environment.SetEnvironmentVariable("GITHUB_STEP_SUMMARY", CreateTempFile());
var extension = new MockExtension();
var reporter = new GitHubReporter(extension);
// Act
var result = await reporter.IsEnabledAsync();
// Assert
result.ShouldBeFalse();
}
[Test]
public async Task IsEnabledAsync_Should_Return_False_When_DISABLE_GITHUB_REPORTER_Is_Set()
{
// Arrange
Environment.SetEnvironmentVariable("DISABLE_GITHUB_REPORTER", "true");
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", "true");
Environment.SetEnvironmentVariable("GITHUB_STEP_SUMMARY", CreateTempFile());
var extension = new MockExtension();
var reporter = new GitHubReporter(extension);
// Act
var result = await reporter.IsEnabledAsync();
// Assert
result.ShouldBeFalse();
}
[Test]
public async Task IsEnabledAsync_Should_Return_False_When_Both_Environment_Variables_Are_Set()
{
// Arrange
Environment.SetEnvironmentVariable("TUNIT_DISABLE_GITHUB_REPORTER", "true");
Environment.SetEnvironmentVariable("DISABLE_GITHUB_REPORTER", "true");
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", "true");
Environment.SetEnvironmentVariable("GITHUB_STEP_SUMMARY", CreateTempFile());
var extension = new MockExtension();
var reporter = new GitHubReporter(extension);
// Act
var result = await reporter.IsEnabledAsync();
// Assert
result.ShouldBeFalse();
}
[Test]
public async Task IsEnabledAsync_Should_Return_False_When_GITHUB_ACTIONS_Is_Not_Set()
{
// Arrange
Environment.SetEnvironmentVariable("TUNIT_DISABLE_GITHUB_REPORTER", null);
Environment.SetEnvironmentVariable("DISABLE_GITHUB_REPORTER", null);
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", null);
Environment.SetEnvironmentVariable("GITHUB_STEP_SUMMARY", CreateTempFile());
var extension = new MockExtension();
var reporter = new GitHubReporter(extension);
// Act
var result = await reporter.IsEnabledAsync();
// Assert
result.ShouldBeFalse();
}
private string CreateTempFile()
{
return Path.GetTempFileName();
}
}