livia-test/MdpC2.Tests/UnitTest1.cs
2025-03-28 14:31:53 +08:00

67 lines
2.7 KiB
C#

using System.Runtime.CompilerServices;
using Livia.Models;
using Livia.Models.Data;
using Livia.Properties;
using Livia.ViewModels;
using Livia.Views.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit.DependencyInjection;
namespace MdpC2.Tests;
internal class Startup
{
public void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<ILogger>(svc => svc.GetRequiredService<ILogger<object>>());
serviceCollection.AddSingleton<IIdleTimer, IdleTimer>();
serviceCollection.AddSingleton<IWarningSystem, WarningSystem>();
serviceCollection.AddSingleton<IVersionUpdateManager, VersionUpdateManager>();
serviceCollection.AddSingleton<IPatientInfoManager, PatientInfoManager>();
serviceCollection.AddSingleton<IRoiLegendManager, RoiLegendManager>();
serviceCollection.AddSingleton<IDataBlockLoader, DataBlockLoader>();
serviceCollection.AddSingleton<ISerialKeyManager, SerialKeyManager>();
serviceCollection.AddSingleton<IAesOperation, AesOperation>();
serviceCollection.AddSingleton<IServerHandler, ServerHandler>();
serviceCollection.AddHttpClient<ILiviaHttpClient, LiviaHttpClient>(x =>
{
x.Timeout = TimeSpan.FromMinutes(10);
UriBuilder uriBuilder = new()
{
Scheme = Settings.Default.ServerPort == 443 ? "https" : "http",
Host = Settings.Default.ServerAddress,
Port = Settings.Default.ServerPort
};
x.BaseAddress = uriBuilder.Uri;
});
serviceCollection.AddSingleton<LiviaHttpClientFactory>();
serviceCollection.AddSingleton<MainWindowViewModel>();
serviceCollection.AddStaFactSupport();
}
}
public class UnitTest1(ILogger logger, IIdleTimer idleTimer, IWarningSystem warningSystem)
{
private readonly ILogger _logger = logger;
private readonly IIdleTimer _idleTimer = idleTimer;
private readonly IWarningSystem _warningSystem = warningSystem;
[ModuleInitializer]
public static void Init() => VerifyXaml.Initialize();
[WpfFact]
public async Task WpfFact_OnSTAThread()
{
Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
Assert.IsType<System.Windows.Threading.DispatcherSynchronizationContext>(SynchronizationContext.Current);
await Task.Yield();
Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState()); // still there
Assert.IsType<System.Windows.Threading.DispatcherSynchronizationContext>(SynchronizationContext.Current);
//var window = new MainWindow(_logger, _idleTimer, _warningSystem);
//await Verify(window);
}
}