using DigitalData.Auth.Abstractions; using DigitalData.Auth.Client; using Microsoft.Extensions.DependencyInjection; namespace DigitalData.Auth.Tests.Client; [TestFixture] public class AuthClientTests { private IAuthClient _client; private static ServiceProvider Build(Action options) => new ServiceCollection() .AddAuthHubClient(options) .BuildServiceProvider(); [SetUp] public async Task Setup() { using var provider = Build(opt => opt.Url = "https://localhost:7192"); _client = provider.GetRequiredService(); await _client.StartAsync(); } [Test] public async Task ReceiveMessage_ShouldCallOnMessageReceived() { // Arrange bool wasCalled = false; using var provider = Build(opt => { opt.Url = "https://localhost:7192"; opt.Events.OnMessageReceived = (user, message, logger) => wasCalled = true; }); var client = provider.GetRequiredService(); string testUser = "TestUser"; string testMessage = "Hello, World!"; // Act await client.ReceiveMessage(testUser, testMessage); // Assert Assert.That(wasCalled, Is.True, "OnMessageReceived was not called."); } }