Skip to content

Commit

Permalink
[ERR] TestNetCore: Message: Initialization method starskytest.starsk…
Browse files Browse the repository at this point in the history
…y.foundation.native.OpenApplicationNative.Helpers.WindowsSetFileAssociationsTests.TestInitialize threw exception. System.IO.IOException: The specified registry key does not exist..
  • Loading branch information
qdraw committed Apr 4, 2024
1 parent cdde545 commit 3d64abb
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Win32;
using starsky.foundation.native.OpenApplicationNative.Helpers;
Expand Down Expand Up @@ -39,21 +40,29 @@ private static void CleanSetup()
}

// Ensure no keys exist before the test starts
Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{Extension}", false);
Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{ProgId}", false);
try
{
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{Extension}", false);
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{ProgId}", false);
}
catch ( IOException )
{
// Ignore if the key does not exist
}
}

[TestMethod]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability",
"CA1416:Validate platform compatibility", Justification = "Check if test for windows only")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability",
"CA1416:Validate platform compatibility",
Justification = "Check if test for windows only")]
public void EnsureAssociationsSet()
{
if ( !new AppSettings().IsWindows )
{
Assert.Inconclusive("This test if for Windows Only");
return;
}

var filePath = new CreateFakeStarskyWindowsExe().FullFilePath;
WindowsSetFileAssociations.EnsureAssociationsSet(
new FileAssociation
Expand All @@ -67,10 +76,10 @@ public void EnsureAssociationsSet()
var registryKeyPath = $@"Software\Classes\{ProgId}\shell\open\command";

using var key = Registry.CurrentUser.OpenSubKey(registryKeyPath);

var valueKey = key?.GetValue(string.Empty)?.ToString();
var pattern = "\"([^\"]*)\"";
Assert.IsNotNull( valueKey );
Assert.IsNotNull(valueKey);
var match = Regex.Match(valueKey, pattern);
var value = match.Groups[1].Value;

Expand Down

0 comments on commit 3d64abb

Please sign in to comment.