Files
AndroidDeviceStreaming/desktop/Ads.Desktop.Tests/DesktopParityTests.cs
T

33 lines
1.7 KiB
C#

using Ads.Desktop;
using System.Reflection;
using System.Text.Json;
using Xunit;
namespace Ads.Desktop.Tests;
public class DesktopParityTests
{
[Fact] public void SeparateEditionsCanOwnTheirLocksAndDuplicateWakesSameEdition()
{
if(!OperatingSystem.IsWindows())return;
var scope=@"Local\TTSTD.ADS.Test."+Guid.NewGuid().ToString("N");
var type=typeof(MainViewModel).Assembly.GetType("Ads.Desktop.DesktopInstance")!;
using var first=(IDisposable)Activator.CreateInstance(type,new object[]{scope+".Avalonia"})!;
using var flutter=new Mutex(true,scope+".Flutter.Instance",out var flutterPrimary);
try {
Assert.True(flutterPrimary);
Assert.True((bool)type.GetProperty("Primary")!.GetValue(first)!);
using var duplicate=(IDisposable)Activator.CreateInstance(type,new object[]{scope+".Avalonia"})!;
Assert.False((bool)type.GetProperty("Primary")!.GetValue(duplicate)!);
using var wake=new ManualResetEventSlim();
type.GetMethod("Listen")!.Invoke(first,new object[]{(Action)(()=>wake.Set())});
type.GetMethod("Activate")!.Invoke(duplicate,null);
Assert.True(wake.Wait(TimeSpan.FromSeconds(3)));
} finally { if(flutterPrimary)flutter.ReleaseMutex(); }
}
[Fact] public void RelayManagementReadsServerNodeConfiguration()
{
var json="""{"id":"relay-1","url":"wss://example.com/relay","connect_address":"127.0.0.1:443","priority":5,"default":true,"healthy":true,"sessions":2,"capacity":32}""";
var node=JsonSerializer.Deserialize<RelayNode>(json,new JsonSerializerOptions(JsonSerializerDefaults.Web))!;
Assert.True(node.Default);Assert.Equal(5,node.Priority);Assert.Equal("127.0.0.1:443",node.ConnectAddress);Assert.Contains("默认",node.Description);
}
}