From b533634e14f07f1d9c33656a1019e0ef16daa84e Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 3 Feb 2025 15:37:19 +0100 Subject: [PATCH] =?UTF-8?q?feat(AuthClientTests):=20ReceiveMessage=5FShoul?= =?UTF-8?q?dCallOnMessageReceived=20Testmethode=20hinzugef=C3=BCgt.=20=20-?= =?UTF-8?q?=20Angeordnete=20Abh=C3=A4ngigkeiten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Client/AuthClientTests.cs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/DigitalData.Auth.Tests/Client/AuthClientTests.cs b/DigitalData.Auth.Tests/Client/AuthClientTests.cs index b05f5fc..500c300 100644 --- a/DigitalData.Auth.Tests/Client/AuthClientTests.cs +++ b/DigitalData.Auth.Tests/Client/AuthClientTests.cs @@ -1,4 +1,5 @@ -using DigitalData.Auth.Client; +using DigitalData.Auth.Abstractions; +using DigitalData.Auth.Client; using Microsoft.Extensions.DependencyInjection; namespace DigitalData.Auth.Tests.Client; @@ -6,13 +7,39 @@ 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 void 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() { - var services = new ServiceCollection(); - services.AddAuthHubClient(opt => + // 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."); } } \ No newline at end of file