diff --git a/DigitalData.Auth.Tests/Client/AuthClientTests.cs b/DigitalData.Auth.Tests/Client/AuthClientTests.cs index 426c56a..109e63b 100644 --- a/DigitalData.Auth.Tests/Client/AuthClientTests.cs +++ b/DigitalData.Auth.Tests/Client/AuthClientTests.cs @@ -17,6 +17,8 @@ public class AuthClientTests private WebApplication? _app = null; + private readonly Queue _disposableAsync = new(); + private static int AvailablePort { get @@ -32,9 +34,16 @@ public class AuthClientTests [SetUp] public void Setup() { - Build = options => new ServiceCollection() - .AddAuthHubClient(options) - .BuildServiceProvider(); + Build = options => + { + var provider = new ServiceCollection() + .AddAuthHubClient(options) + .BuildServiceProvider(); + + _disposableAsync.Enqueue(provider); + + return provider; + }; // Create and run test server // Create builder and add SignalR service @@ -49,6 +58,8 @@ public class AuthClientTests _app.Urls.Add(url); _app.MapHub(hubRoute); _app.Start(); + + _disposableAsync.Enqueue(_app); } [TearDown] @@ -58,16 +69,18 @@ public class AuthClientTests if (_app is not null) { await _app.StopAsync(); - await _app.DisposeAsync(); Console.WriteLine("Test server stopped."); } + + while (_disposableAsync.Count > 0) + await _disposableAsync.Dequeue().DisposeAsync(); } [Test] public async Task StartAsync_ShouldConnectSuccessfully() { // Arrange - using var provider = Build(opt => opt.Url = _hubUrl); + var provider = Build(opt => opt.Url = _hubUrl); var client = provider.GetRequiredService(); // Act @@ -90,12 +103,12 @@ public class AuthClientTests string rcv_key = string.Empty; // 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(); await sender_client.StartAsync(); // Receiver client - using var provider_receiver = Build(opt => + var provider_receiver = Build(opt => { opt.Url = _hubUrl; opt.Events.OnMessageReceived = (topic, key, logger) =>