-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPopulateAppSettingsTests.cs
More file actions
76 lines (61 loc) · 1.93 KB
/
PopulateAppSettingsTests.cs
File metadata and controls
76 lines (61 loc) · 1.93 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
namespace ServiceControl.UnitTests;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using NUnit.Framework;
[TestFixture]
public class PopulateAppSettingsTests
{
[Test]
public async Task Should_populate_appSettings_from_exe_config_file()
{
const string MagicValue = "7303A0AA-1003-4DC4-823B-4E8B2A35CF57";
var config = $"""
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ServiceControl/LogPath" value="{MagicValue}" />
</appSettings>
</configuration>
""";
await File.WriteAllTextAsync("ServiceControl.exe.config", config);
var fileName = "ServiceControl";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
fileName = "ServiceControl.exe";
}
var startInfo = new ProcessStartInfo(fileName)
{
RedirectStandardOutput = true,
UseShellExecute = false
};
var p = Process.Start(startInfo);
if (p == null)
{
throw new Exception("Failed to start ServiceControl");
}
var pathIsSet = false;
var outputTask = Task.Run(async () =>
{
while (!p.StandardOutput.EndOfStream)
{
var line = await p.StandardOutput.ReadLineAsync();
if (line.Contains($"Logging to {MagicValue}"))
{
pathIsSet = true;
p.Kill(true);
}
}
});
if (!p.WaitForExit(5000))
{
p.Kill(true);
}
await outputTask;
Assert.That(pathIsSet, Is.True);
}
[TearDown]
public void TearDown() => File.Delete("ServiceControl.exe.config");
}