using AyCode.Core; using AyCode.Core.Extensions; using AyCode.Core.Tests.TestModels; using AyCode.Services.Server.SignalRs; using AyCode.Services.SignalRs; using AyCode.Services.Tests.SignalRs; using Microsoft.AspNetCore.SignalR.Client; namespace AyCode.Services.Server.Tests.SignalRs; /// /// Testable SignalR client that allows testing without real HubConnection. /// public class TestableSignalRClient2 : AcSignalRClientBase, IAcSignalRHubItemServer { private HubConnectionState _connectionState = HubConnectionState.Connected; private readonly TestableSignalRHub2 _signalRHub; /// /// Testable SignalR client that allows testing without real HubConnection. /// public TestableSignalRClient2(TestableSignalRHub2 signalRHub, TestLogger logger) : base(logger) { MsDelay = 0; MsFirstDelay = 0; _signalRHub = signalRHub; } #region Override virtual methods for testing protected override async Task MessageReceived(int messageTag, byte[] messageBytes) { throw new NotImplementedException(); } protected override HubConnectionState GetConnectionState() => _connectionState; protected override bool IsConnected() => _connectionState == HubConnectionState.Connected; protected override Task StartConnectionInternal() { _connectionState = HubConnectionState.Connected; return Task.CompletedTask; } protected override Task StopConnectionInternal() { _connectionState = HubConnectionState.Disconnected; return Task.CompletedTask; } protected override ValueTask DisposeConnectionInternal() => ValueTask.CompletedTask; protected override async Task SendToHubAsync(int messageTag, byte[]? messageBytes, int? requestId) { await _signalRHub.OnReceiveMessage(messageTag, messageBytes, requestId); } #endregion }