Replaces NullCommandBus.Instance in PanelContext with a real LiveCommandBus when a live session is active. Panels publish SendChatCmd; the host routes it to the right wire opcode + emits a ChatLog.OnSelfSent local echo (optimistic; retail-equivalent for Talk). Pieces: - ChatChannelKind enum (UI.Abstractions) - mirrors holtburger's ChatChannelKind (references/holtburger/.../client/types.rs:35-49). - SendChatCmd record (UI.Abstractions) - (Channel, TargetName?, Text). - LiveCommandBus (UI.Abstractions) - single-handler-per-type; Register<T> throws on double-register; Publish<T> logs missing handler but does not throw. - ChannelResolver (UI.Abstractions) - port of holtburger's resolve_legacy_channel (client/commands.rs:50-62) mapping ChatChannelKind to legacy ChatChannel ids verbatim from holtburger-protocol/.../chat/types.rs:8-24 (Fellow=0x0800, AllegianceBroadcast=0x02000000, Vassals=0x1000, Patron=0x2000, Monarch=0x4000, CoVassals=0x01000000). - WorldSession.SendTalk / SendTell / SendChannel - 3-line wrappers around existing ChatRequests.Build* + SendGameAction. Internal GameActionCapture seam + InternalsVisibleTo for tests. - GameWindow registers SendChatCmd handler: Say -> SendTalk + ChatLog echo, Tell -> SendTell + echo, channel kinds -> ChannelResolver.Resolve -> SendChannel + echo. 12 new tests across SendChatCmd + LiveCommandBus + ChannelResolver + WorldSessionChat. NullCommandBus.Instance retained for back-compat when no live session. Solution total: 893 green (51 + 229 + 613). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
namespace AcDream.UI.Abstractions.Tests;
|
|
|
|
public sealed class LiveCommandBusTests
|
|
{
|
|
private sealed record FakeCmd(int Value);
|
|
private sealed record OtherCmd(string Tag);
|
|
|
|
[Fact]
|
|
public void Publish_InvokesRegisteredHandler_ForMatchingType()
|
|
{
|
|
var bus = new LiveCommandBus();
|
|
FakeCmd? captured = null;
|
|
bus.Register<FakeCmd>(c => captured = c);
|
|
|
|
bus.Publish(new FakeCmd(42));
|
|
|
|
Assert.NotNull(captured);
|
|
Assert.Equal(42, captured!.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Publish_DoesNotThrow_WhenNoHandlerRegistered()
|
|
{
|
|
var bus = new LiveCommandBus();
|
|
|
|
// No handler for OtherCmd — must not throw.
|
|
bus.Publish(new OtherCmd("x"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Register_Twice_ForSameType_Throws()
|
|
{
|
|
var bus = new LiveCommandBus();
|
|
bus.Register<FakeCmd>(_ => { });
|
|
|
|
Assert.Throws<InvalidOperationException>(() => bus.Register<FakeCmd>(_ => { }));
|
|
}
|
|
}
|
|
|
|
public sealed class ChannelResolverTests
|
|
{
|
|
[Fact]
|
|
public void Resolve_LegacyChannels_MatchesHoltburgerIds()
|
|
{
|
|
// Holtburger references/holtburger/crates/holtburger-protocol/src/messages/chat/types.rs:8-24
|
|
// and holtburger-core/src/client/commands.rs:50-62. Six legacy channels
|
|
// map to known ChatChannel ids; the rest fall through to TurbineChat.
|
|
Assert.Equal((0x00000800u, "Fellowship"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.Fellowship)));
|
|
Assert.Equal((0x02000000u, "Allegiance"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.Allegiance)));
|
|
Assert.Equal((0x00001000u, "Vassals"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.Vassals)));
|
|
Assert.Equal((0x00002000u, "Patron"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.Patron)));
|
|
Assert.Equal((0x00004000u, "Monarch"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.Monarch)));
|
|
Assert.Equal((0x01000000u, "CoVassals"), AsTuple(ChannelResolver.Resolve(ChatChannelKind.CoVassals)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_NonLegacyChannels_ReturnsNull()
|
|
{
|
|
// Say + Tell are handled separately by the SendChatCmd dispatcher.
|
|
// General/Trade/etc. require a TurbineChat channel id we don't yet wire.
|
|
Assert.Null(ChannelResolver.Resolve(ChatChannelKind.Say));
|
|
Assert.Null(ChannelResolver.Resolve(ChatChannelKind.Tell));
|
|
Assert.Null(ChannelResolver.Resolve(ChatChannelKind.General));
|
|
Assert.Null(ChannelResolver.Resolve(ChatChannelKind.Trade));
|
|
Assert.Null(ChannelResolver.Resolve(ChatChannelKind.Unknown));
|
|
}
|
|
|
|
private static (uint ChannelId, string DisplayName) AsTuple(ChannelResolver.Resolved? r)
|
|
{
|
|
Assert.NotNull(r);
|
|
return (r!.Value.ChannelId, r.Value.DisplayName);
|
|
}
|
|
}
|