28 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using IM.Domain.Common;
namespace BuildFlow.IM.Integration.Tests;
/// <summary>
/// 进程内 <see cref="IUserInfoService"/> 替身:避免真实 gRPC 调用到未运行的 SSO 服务。
/// 测试前调用 <see cref="SetUser"/> 预置用户展示名/头像,Handler 调用时按 ID 返回。
/// </summary>
public sealed class InMemoryUserInfoService : IUserInfoService
{
private readonly Dictionary<Guid, (string Username, string? Avatar)> _users = new();
public void SetUser(Guid userId, string username, string? avatar = null) =>
_users[userId] = (username, avatar);
public Task<Dictionary<string, (string Username, string? Avatar)>> GetUsersAsync(
IEnumerable<Guid> userIds, CancellationToken ct = default)
{
var result = new Dictionary<string, (string Username, string? Avatar)>();
foreach (var id in userIds)
{
if (_users.TryGetValue(id, out var info))
result[id.ToString()] = info;
}
return Task.FromResult(result);
}
}