feat(AuthClientTests): ReceiveMessage_ShouldCallOnMessageReceived Testmethode hinzugefügt.

- Angeordnete Abhängigkeiten
This commit is contained in:
Developer 02 2025-02-03 15:37:19 +01:00
parent 766e4e6d27
commit b533634e14

View File

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