-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsUpdateInstallerLauncherTests.cs
More file actions
88 lines (70 loc) · 3.11 KB
/
Copy pathWindowsUpdateInstallerLauncherTests.cs
File metadata and controls
88 lines (70 loc) · 3.11 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
using System.Diagnostics;
using SwitchifyPc.Core.Updates;
using SwitchifyPc.Windows.Updates;
namespace SwitchifyPc.Tests;
public sealed class WindowsUpdateInstallerLauncherTests
{
[Fact]
public async Task ReturnsInstallerUnavailableWhenInstallerPathIsMissing()
{
FakeProcessShell shell = new();
WindowsUpdateInstallerLauncher launcher = new(shell, _ => false);
UpdateInstallerLaunchResult result = await launcher.LaunchAsync(@"C:\cache\missing.exe");
Assert.False(result.Ok);
Assert.Equal(UpdateInstallFailureReason.InstallerUnavailable, result.Reason);
Assert.Null(shell.LastStartInfo);
}
[Fact]
public async Task ReturnsInstallerUnavailableWhenInstallerPathIsNull()
{
FakeProcessShell shell = new();
WindowsUpdateInstallerLauncher launcher = new(shell, _ => true);
UpdateInstallerLaunchResult result = await launcher.LaunchAsync(null);
Assert.False(result.Ok);
Assert.Equal(UpdateInstallFailureReason.InstallerUnavailable, result.Reason);
Assert.Null(shell.LastStartInfo);
}
[Fact]
public async Task OpensInstallerThroughWindowsShell()
{
FakeProcessShell shell = new();
WindowsUpdateInstallerLauncher launcher = new(shell, _ => true);
UpdateInstallerLaunchResult result = await launcher.LaunchAsync(@"C:\cache\Switchify-PC-Setup-0.2.0-x64.exe");
Assert.True(result.Ok);
Assert.NotNull(shell.LastStartInfo);
Assert.Equal(@"C:\cache\Switchify-PC-Setup-0.2.0-x64.exe", shell.LastStartInfo.FileName);
Assert.True(shell.LastStartInfo.UseShellExecute);
Assert.Equal(ProcessWindowStyle.Normal, shell.LastStartInfo.WindowStyle);
Assert.Equal(@"C:\cache", shell.LastStartInfo.WorkingDirectory);
}
[Fact]
public async Task ReturnsLaunchFailedWhenShellReturnsFalse()
{
FakeProcessShell shell = new() { StartResult = false };
WindowsUpdateInstallerLauncher launcher = new(shell, _ => true);
UpdateInstallerLaunchResult result = await launcher.LaunchAsync(@"C:\cache\setup.exe");
Assert.False(result.Ok);
Assert.Equal(UpdateInstallFailureReason.InstallerLaunchFailed, result.Reason);
}
[Fact]
public async Task ReturnsLaunchFailedWhenShellThrows()
{
FakeProcessShell shell = new() { ThrowOnStart = true };
WindowsUpdateInstallerLauncher launcher = new(shell, _ => true);
UpdateInstallerLaunchResult result = await launcher.LaunchAsync(@"C:\cache\setup.exe");
Assert.False(result.Ok);
Assert.Equal(UpdateInstallFailureReason.InstallerLaunchFailed, result.Reason);
}
private sealed class FakeProcessShell : IProcessShell
{
public ProcessStartInfo? LastStartInfo { get; private set; }
public bool StartResult { get; init; } = true;
public bool ThrowOnStart { get; init; }
public bool Start(ProcessStartInfo startInfo)
{
LastStartInfo = startInfo;
if (ThrowOnStart) throw new InvalidOperationException("Could not start process.");
return StartResult;
}
}
}