65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
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 MessagePack.Resolvers;
|
|
using Microsoft.AspNetCore.SignalR.Client;
|
|
|
|
namespace AyCode.Services.Server.Tests.SignalRs;
|
|
|
|
/// <summary>
|
|
/// Testable SignalR client that allows testing without real HubConnection.
|
|
/// </summary>
|
|
public class TestableSignalRClient2 : AcSignalRClientBase, IAcSignalRHubItemServer
|
|
{
|
|
private HubConnectionState _connectionState = HubConnectionState.Connected;
|
|
private readonly TestableSignalRHub2 _signalRHub;
|
|
|
|
/// <summary>
|
|
/// Testable SignalR client that allows testing without real HubConnection.
|
|
/// </summary>
|
|
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
|
|
|
|
}
|
|
|
|
|