Introduce WindowsStartupHelper
ADD
WalletWasabi.Tests/Helpers/WindowsStartupHelper.cs
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WalletWasabi.Tests.Helpers
+{
+ public class WindowsStartupHelper
+ {
+ private const string PathToRegistyKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
+
+ public bool RegistryKeyExists()
+ {
+ bool result = false;
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey(PathToRegistyKey, false);
+ result = registryKey.GetValueNames().Contains(nameof(WalletWasabi));
+ }
+
+ return result;
+ }
+ }
+}

MODIFY
WalletWasabi.Tests/UnitTests/StartWasabiOnSystemStartupTests.cs
WalletWasabi.Tests/UnitTests/StartWasabiOnSystemStartupTests.cs
@@ -10,28 +10,16 @@ using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Gui;
using WalletWasabi.Helpers;
using WalletWasabi.Microservices;
+using WalletWasabi.Tests.Helpers;
using Xunit;
namespace WalletWasabi.Tests.UnitTests
{
public class StartWasabiOnSystemStartupTests
{
- private const string PathToRegistyKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
-
private string _listCmd = $"osascript -e \' tell application \"System Events\" to get every login item\'";
- // Path to Wasabi.desktop file. Only Linux distributions need this.
- private string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "autostart", "Wasabi.desktop");
-
- private string _expectedDesktopFileContent = string.Join(
- "\n",
- "[Desktop Entry]",
- $"Name={Constants.AppName}",
- "Type=Application",
- $"Exec={EnvironmentHelpers.GetExecutablePath()}",
- "Hidden=false",
- "Terminal=false",
- "X-GNOME-Autostart-enabled=true");
+ private readonly WindowsStartupHelper _windowsHelper = new();
[Fact]
public async Task ModifyStartupOnDifferentSystemsTestAsync()
@@ -42,22 +30,22 @@ namespace WalletWasabi.Tests.UnitTests
{
await StartupHelper.ModifyStartupSettingAsync(true);
- Assert.True(RegistryKeyExists());
+ Assert.True(_windowsHelper.RegistryKeyExists());
await StartupHelper.ModifyStartupSettingAsync(false);
- Assert.False(RegistryKeyExists());
+ Assert.False(_windowsHelper.RegistryKeyExists());
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
await StartupHelper.ModifyStartupSettingAsync(true);
- Assert.True(File.Exists(_filePath));
- Assert.Equal(_expectedDesktopFileContent, GetFileContent(_filePath));
+ //Assert.True(File.Exists(_linuxHelper.FilePath));
+ //Assert.Equal(_linuxHelper.ExpectedDesktopFileContent, _linuxHelper.GetFileContent());
await StartupHelper.ModifyStartupSettingAsync(false);
- Assert.False(File.Exists(_filePath));
+ //Assert.False(File.Exists(_linuxHelper.FilePath));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
@@ -87,24 +75,6 @@ namespace WalletWasabi.Tests.UnitTests
return uiConfig;
}
- private bool RegistryKeyExists()
- {
- bool result = false;
-
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey(PathToRegistyKey, false);
- result = registryKey.GetValueNames().Contains(nameof(WalletWasabi));
- }
-
- return result;
- }
-
- private string GetFileContent(string filePath)
- {
- return string.Join("\n", File.ReadAllLines(filePath));
- }
-
private async Task<string> GetLoginItemsAsync(string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");

Introduce WindowsStartupHelper