-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDiffRunnerTests.cs
135 lines (124 loc) · 3.74 KB
/
DiffRunnerTests.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#if NETCOREAPP3_1
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DiffEngine;
using Xunit;
using Xunit.Abstractions;
public class DiffRunnerTests :
XunitContextBase
{
static ResolvedTool tool;
string file2;
string file1;
string command;
[Fact(Skip = "Explicit")]
public async Task MaxInstancesToLaunch()
{
DiffRunner.MaxInstancesToLaunch(1);
try
{
await Task.Delay(500);
ProcessCleanup.Refresh();
var result = await DiffRunner.Launch(file1, "fake.txt");
await Task.Delay(300);
Assert.Equal(LaunchResult.StartedNewInstance, result);
ProcessCleanup.Refresh();
result = await DiffRunner.Launch(file2, "fake.txt");
Assert.Equal(LaunchResult.TooManyRunningDiffTools, result);
ProcessCleanup.Refresh();
DiffRunner.Kill(file1, "fake.txt");
DiffRunner.Kill(file2, "fake.txt");
}
finally
{
DiffRunner.MaxInstancesToLaunch(5);
}
}
async Task Launch()
{
string targetFile = "";
string tempFile = "";
#region DiffRunnerLaunch
await DiffRunner.Launch(tempFile, targetFile);
#endregion
}
[Fact(Skip = "Explicit")]
public async Task Kill()
{
await DiffRunner.Launch(file1, file2);
ProcessCleanup.Refresh();
#region DiffRunnerKill
DiffRunner.Kill(file1, file2);
#endregion
}
[Fact]
public async Task LaunchAndKillDisabled()
{
DiffRunner.Disabled = true;
try
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.Disabled, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
DiffRunner.Kill(file1, file2);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
}
finally
{
DiffRunner.Disabled = false;
}
}
[Fact]
public async Task LaunchAndKill()
{
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
var result = await DiffRunner.Launch(file1, file2);
Assert.Equal(LaunchResult.StartedNewInstance, result);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.True(IsRunning());
Assert.True(ProcessCleanup.IsRunning(command));
DiffRunner.Kill(file1, file2);
Thread.Sleep(500);
ProcessCleanup.Refresh();
Assert.False(IsRunning());
Assert.False(ProcessCleanup.IsRunning(command));
}
static bool IsRunning()
{
return ProcessCleanup
.FindAll()
.Any(x => x.Command.Contains("FakeDiffTool"));
}
public DiffRunnerTests(ITestOutputHelper output) :
base(output)
{
file1 = Path.Combine(SourceDirectory, "DiffRunner.file1.txt");
file2 = Path.Combine(SourceDirectory, "DiffRunner.file2.txt");
command = tool.BuildCommand(file1, file2);
}
static DiffRunnerTests()
{
tool = DiffTools.AddTool(
name: "FakeDiffTool",
autoRefresh: true,
isMdi: false,
supportsText: true,
requiresTarget: true,
arguments: (path1, path2) => $"\"{path1}\" \"{path2}\"",
exePath: FakeDiffTool.Exe,
binaryExtensions: new[] {"knownBin"})!;
}
}
#endif