first commit
This commit is contained in:
39
Nitrox.Test/Model/Platforms/OS/Windows/RegistryTest.cs
Normal file
39
Nitrox.Test/Model/Platforms/OS/Windows/RegistryTest.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Runtime.Versioning;
|
||||
using System.Threading.Tasks;
|
||||
using Nitrox.Test.Model.Platforms;
|
||||
|
||||
namespace NitroxModel.Platforms.OS.Windows;
|
||||
|
||||
[TestClass]
|
||||
[SupportedOSPlatform("windows")]
|
||||
public class RegistryTest
|
||||
{
|
||||
[OSTestMethod("windows")]
|
||||
public async Task WaitsForRegistryKeyToExist()
|
||||
{
|
||||
const string PATH_TO_KEY = @"SOFTWARE\Nitrox\test";
|
||||
|
||||
RegistryEx.Write(PATH_TO_KEY, 0);
|
||||
Task<bool> readTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await RegistryEx.CompareWaitAsync<int>(PATH_TO_KEY,
|
||||
v => v == 1337,
|
||||
TimeSpan.FromSeconds(5));
|
||||
return true;
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
RegistryEx.Write(PATH_TO_KEY, 1337);
|
||||
Assert.IsTrue(await readTask);
|
||||
|
||||
// Cleanup (we can keep "Nitrox" key intact).
|
||||
RegistryEx.Delete(PATH_TO_KEY);
|
||||
Assert.IsNull(RegistryEx.Read<string>(PATH_TO_KEY));
|
||||
}
|
||||
}
|
32
Nitrox.Test/Model/Platforms/OSTestMethodAttribute.cs
Normal file
32
Nitrox.Test/Model/Platforms/OSTestMethodAttribute.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace Nitrox.Test.Model.Platforms;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class OSTestMethodAttribute : TestMethodAttribute
|
||||
{
|
||||
public string Platform { get;}
|
||||
|
||||
/// <summary>
|
||||
/// Test method attribute, that will only run the test on the specified platform.
|
||||
/// </summary>
|
||||
/// <param name="platform">case insensitive platform, i.e: linux, windows, osx</param>
|
||||
public OSTestMethodAttribute(string platform)
|
||||
{
|
||||
Platform = platform;
|
||||
}
|
||||
|
||||
public override TestResult[] Execute(ITestMethod testMethod)
|
||||
{
|
||||
if (!OperatingSystem.IsOSPlatform(Platform))
|
||||
{
|
||||
return [
|
||||
new TestResult()
|
||||
{
|
||||
Outcome = UnitTestOutcome.Inconclusive,
|
||||
TestContextMessages = $"This test can only be run on {Platform}"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
return base.Execute(testMethod);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user