-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPopulateAppSettingsTests.cs
More file actions
80 lines (63 loc) · 2.04 KB
/
PopulateAppSettingsTests.cs
File metadata and controls
80 lines (63 loc) · 2.04 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
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
{
const string ConfigFileName = "ServiceControl.Monitoring.exe.config";
[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="Monitoring/LogPath" value="{MagicValue}" />
</appSettings>
</configuration>
""";
await File.WriteAllTextAsync(ConfigFileName, config);
var fileName = "ServiceControl.Monitoring";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
fileName = "ServiceControl.Monitoring.exe";
}
var startInfo = new ProcessStartInfo(fileName)
{
RedirectStandardOutput = true,
UseShellExecute = false
};
var p = Process.Start(startInfo);
if (p == null)
{
throw new Exception($"Failed to start {fileName}");
}
var pathIsSet = false;
var outputTask = Task.Run(async () =>
{
while (!p.StandardOutput.EndOfStream)
{
var line = await p.StandardOutput.ReadLineAsync();
Console.WriteLine(line);
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(ConfigFileName);
}