fix(AuthClientTests): Aktualisiert um Anbieter zu entsorgen

This commit is contained in:
Developer 02 2025-02-05 10:38:45 +01:00
parent b6d86d3d0d
commit 64717fbba5

View File

@ -17,6 +17,8 @@ public class AuthClientTests
private WebApplication? _app = null; private WebApplication? _app = null;
private readonly Queue<IAsyncDisposable> _disposableAsync = new();
private static int AvailablePort private static int AvailablePort
{ {
get get
@ -32,10 +34,17 @@ public class AuthClientTests
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
Build = options => new ServiceCollection() Build = options =>
{
var provider = new ServiceCollection()
.AddAuthHubClient(options) .AddAuthHubClient(options)
.BuildServiceProvider(); .BuildServiceProvider();
_disposableAsync.Enqueue(provider);
return provider;
};
// Create and run test server // Create and run test server
// Create builder and add SignalR service // Create builder and add SignalR service
var builder = WebApplication.CreateBuilder(); var builder = WebApplication.CreateBuilder();
@ -49,6 +58,8 @@ public class AuthClientTests
_app.Urls.Add(url); _app.Urls.Add(url);
_app.MapHub<AuthHub>(hubRoute); _app.MapHub<AuthHub>(hubRoute);
_app.Start(); _app.Start();
_disposableAsync.Enqueue(_app);
} }
[TearDown] [TearDown]
@ -58,16 +69,18 @@ public class AuthClientTests
if (_app is not null) if (_app is not null)
{ {
await _app.StopAsync(); await _app.StopAsync();
await _app.DisposeAsync();
Console.WriteLine("Test server stopped."); Console.WriteLine("Test server stopped.");
} }
while (_disposableAsync.Count > 0)
await _disposableAsync.Dequeue().DisposeAsync();
} }
[Test] [Test]
public async Task StartAsync_ShouldConnectSuccessfully() public async Task StartAsync_ShouldConnectSuccessfully()
{ {
// Arrange // Arrange
using var provider = Build(opt => opt.Url = _hubUrl); var provider = Build(opt => opt.Url = _hubUrl);
var client = provider.GetRequiredService<IAuthClient>(); var client = provider.GetRequiredService<IAuthClient>();
// Act // Act
@ -90,12 +103,12 @@ public class AuthClientTests
string rcv_key = string.Empty; string rcv_key = string.Empty;
// Sender client // Sender client
using var provider_sender = Build(opt => opt.Url = _hubUrl); var provider_sender = Build(opt => opt.Url = _hubUrl);
var sender_client = provider_sender.GetRequiredService<IAuthClient>(); var sender_client = provider_sender.GetRequiredService<IAuthClient>();
await sender_client.StartAsync(); await sender_client.StartAsync();
// Receiver client // Receiver client
using var provider_receiver = Build(opt => var provider_receiver = Build(opt =>
{ {
opt.Url = _hubUrl; opt.Url = _hubUrl;
opt.Events.OnMessageReceived = (topic, key, logger) => opt.Events.OnMessageReceived = (topic, key, logger) =>