|
| 1 | +#if NET5_0_OR_GREATER |
| 2 | +[System.Runtime.Versioning.SupportedOSPlatform("windows")] |
| 3 | +#endif |
| 4 | +public class WindowsProcessTests(ITestOutputHelper output) : |
| 5 | + XunitContextBase(output) |
| 6 | +{ |
| 7 | + [Theory] |
| 8 | + [InlineData("\"C:\\Program Files\\Beyond Compare 4\\BComp.exe\" C:\\temp\\file.1.txt C:\\temp\\file.2.txt", true)] |
| 9 | + [InlineData("notepad.exe C:\\Users\\test\\doc.1.txt C:\\Users\\test\\doc.2.txt", true)] |
| 10 | + [InlineData("\"C:\\diff\\tool.exe\" D:\\path\\to\\source.1.cs D:\\path\\to\\target.2.cs", true)] |
| 11 | + [InlineData("code.exe --diff file.a.b file.c.d", true)] |
| 12 | + [InlineData("app.exe path.with.dots path.more.dots", true)] |
| 13 | + public void MatchesPattern_WithTwoFilePaths_ReturnsTrue(string commandLine, bool expected) |
| 14 | + { |
| 15 | + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 16 | + { |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + Assert.Equal(expected, WindowsProcess.MatchesPattern(commandLine)); |
| 21 | + } |
| 22 | + |
| 23 | + [Theory] |
| 24 | + [InlineData("notepad.exe")] |
| 25 | + [InlineData("notepad.exe C:\\temp\\file.txt")] |
| 26 | + [InlineData("cmd.exe /c dir")] |
| 27 | + [InlineData("explorer.exe")] |
| 28 | + [InlineData("")] |
| 29 | + [InlineData("singleword")] |
| 30 | + [InlineData("app.exe onepath.with.dots")] |
| 31 | + public void MatchesPattern_WithoutTwoFilePaths_ReturnsFalse(string commandLine) |
| 32 | + { |
| 33 | + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 34 | + { |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + Assert.False(WindowsProcess.MatchesPattern(commandLine)); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void FindAll_ReturnsProcessCommands() |
| 43 | + { |
| 44 | + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 45 | + { |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + var result = WindowsProcess.FindAll(); |
| 50 | + Assert.NotNull(result); |
| 51 | + foreach (var cmd in result) |
| 52 | + { |
| 53 | + Debug.WriteLine($"{cmd.Process}: {cmd.Command}"); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments