using AyCode.Core.Extensions;
using AyCode.Services.SignalRs;
using MessagePack;
using MessagePack.Resolvers;
namespace AyCode.Services.Server.Tests.SignalRs;
///
/// Helper methods for creating SignalR test messages.
/// Uses the production SignalR types for compatibility with the actual client/server code.
///
public static class SignalRTestHelper
{
private static readonly MessagePackSerializerOptions MessagePackOptions = ContractlessStandardResolver.Options;
///
/// Creates a MessagePack message for parameters using IdMessage format.
/// Each parameter is serialized directly as JSON (no array wrapping).
///
public static byte[] CreatePrimitiveParamsMessage(params object[] values)
{
var idMessage = new IdMessage(values);
var postMessage = new SignalPostJsonDataMessage(idMessage);
return MessagePackSerializer.Serialize(postMessage, MessagePackOptions);
}
///
/// Creates a MessagePack message for a single primitive parameter.
///
public static byte[] CreateSinglePrimitiveMessage(T value) where T : notnull
{
return CreatePrimitiveParamsMessage(value);
}
///
/// Creates a MessagePack message for a complex object parameter.
/// Uses PostDataJson pattern for single complex objects.
///
public static byte[] CreateComplexObjectMessage(T obj)
{
var json = obj.ToJson();
var postMessage = new SignalPostJsonDataMessage