Удалены <remarks>, <summary> сжаты до короткой фразы, вырезаны ссылки на Task/Ruling/этап/python/прототип; //-комментарии со ссылками на процесс удалены; то же в .proto. Правила обновлены в docs/spec/Код-стайл-Дейл.md. Строк комментариев 27210 -> ~19100.
129 lines
4.5 KiB
C#
129 lines
4.5 KiB
C#
using Deal.Telegram.Dialogs;
|
|
|
|
namespace Deal.Telegram.Tests.Telegram;
|
|
|
|
/// <summary>
|
|
/// Unit-тесты зеркала каталога/мониторинга диалогов.
|
|
/// </summary>
|
|
public sealed class DialogCatalogTests
|
|
{
|
|
private const string TenantA = "tenant-a";
|
|
private const string TenantB = "tenant-b";
|
|
private const string ChannelId = "-1001234567890";
|
|
private const string GroupId = "-456789";
|
|
private const string UserId = "+12345";
|
|
|
|
/// <summary>
|
|
/// SetMonitored включает/выключает диалог; IsMonitored повторяет решение.
|
|
/// </summary>
|
|
[Fact]
|
|
public void SetMonitored_TogglesDialog()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
|
|
Assert.False(catalog.IsMonitored(TenantA, ChannelId));
|
|
|
|
catalog.SetMonitored(TenantA, ChannelId, enabled: true);
|
|
Assert.True(catalog.IsMonitored(TenantA, ChannelId));
|
|
|
|
catalog.SetMonitored(TenantA, ChannelId, enabled: false);
|
|
Assert.False(catalog.IsMonitored(TenantA, ChannelId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Мониторинг изолирован по тенантам
|
|
/// </summary>
|
|
[Fact]
|
|
public void Monitored_IsIsolatedPerTenant()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
catalog.SetMonitored(TenantA, ChannelId, enabled: true);
|
|
|
|
Assert.True(catalog.IsMonitored(TenantA, ChannelId));
|
|
Assert.False(catalog.IsMonitored(TenantB, ChannelId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// SetMonitorAll(true) мониторит каталог и возвращает его размер; false — снимает всё.
|
|
/// </summary>
|
|
[Fact]
|
|
public void SetAllMonitored_EnablesKnownDialogs_AndReturnsCount()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
catalog.ReplaceKnown(TenantA, [ChannelId, GroupId, UserId]);
|
|
|
|
int count = catalog.SetAllMonitored(TenantA, enabled: true);
|
|
|
|
Assert.Equal(3, count);
|
|
Assert.True(catalog.IsMonitored(TenantA, ChannelId));
|
|
Assert.True(catalog.IsMonitored(TenantA, GroupId));
|
|
Assert.True(catalog.IsMonitored(TenantA, UserId));
|
|
|
|
catalog.SetAllMonitored(TenantA, enabled: false);
|
|
Assert.False(catalog.IsMonitored(TenantA, ChannelId));
|
|
Assert.False(catalog.IsMonitored(TenantA, GroupId));
|
|
Assert.Equal(3, catalog.KnownCount(TenantA));
|
|
}
|
|
|
|
/// <summary>
|
|
/// SetMonitorAll(true) сохраняет мониторинг записей вне каталога
|
|
/// </summary>
|
|
[Fact]
|
|
public void SetAllMonitored_TrueKeepsExistingMonitoredOutsideKnown()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
catalog.SetMonitored(TenantA, UserId, enabled: true);
|
|
|
|
catalog.SetAllMonitored(TenantA, enabled: true);
|
|
|
|
Assert.True(catalog.IsMonitored(TenantA, UserId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Актуализация ответом SyncDialogs
|
|
/// </summary>
|
|
[Fact]
|
|
public void ReplaceMonitored_OverridesMirror_WithCoreReply()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
catalog.SetMonitored(TenantA, GroupId, enabled: true);
|
|
catalog.SetMonitored(TenantA, UserId, enabled: true);
|
|
|
|
catalog.ReplaceKnown(TenantA, [ChannelId, GroupId]);
|
|
catalog.ReplaceMonitored(TenantA, [GroupId]);
|
|
|
|
Assert.False(catalog.IsMonitored(TenantA, UserId)); // ядро сняло мониторинг (нет в каталоге)
|
|
Assert.True(catalog.IsMonitored(TenantA, GroupId));
|
|
Assert.False(catalog.IsMonitored(TenantA, ChannelId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset (Logout) очищает каталог и мониторинг тенанта (`.clear`).
|
|
/// </summary>
|
|
[Fact]
|
|
public void Reset_ClearsTenantState()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
catalog.ReplaceKnown(TenantA, [ChannelId]);
|
|
catalog.SetMonitored(TenantA, ChannelId, enabled: true);
|
|
|
|
catalog.Reset(TenantA);
|
|
|
|
Assert.Equal(0, catalog.KnownCount(TenantA));
|
|
Assert.False(catalog.IsMonitored(TenantA, ChannelId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Каталог пустого тенанта
|
|
/// </summary>
|
|
[Fact]
|
|
public void UnknownTenant_ReportsEmptyState()
|
|
{
|
|
var catalog = new DialogCatalog();
|
|
|
|
Assert.Equal(0, catalog.KnownCount(TenantB));
|
|
Assert.False(catalog.IsMonitored(TenantB, ChannelId));
|
|
Assert.Empty(catalog.SnapshotMonitored(TenantB));
|
|
}
|
|
}
|