Compare commits
2 Commits
5f9926e911
...
64717fbba5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64717fbba5 | ||
|
|
b6d86d3d0d |
@ -69,5 +69,6 @@ public class AuthClient : IAuthClient, IAsyncDisposable
|
||||
{
|
||||
await _connection.StopAsync();
|
||||
await _connection.DisposeAsync();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,8 @@ public class AuthClientTests
|
||||
|
||||
private WebApplication? _app = null;
|
||||
|
||||
private readonly Queue<IAsyncDisposable> _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<AuthHub>(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<IAuthClient>();
|
||||
|
||||
// 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<IAuthClient>();
|
||||
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) =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user