acdream/tests/AcDream.Runtime.Tests/Chat/LiveChatCommandRouteTests.cs

59 lines
2.1 KiB
C#

using AcDream.Core.Chat;
using AcDream.Runtime.Chat;
using AcDream.Runtime.Gameplay;
namespace AcDream.Runtime.Tests.Chat;
public sealed class LiveChatCommandRouteTests
{
[Fact]
public void FourRegistrationsPreserveOrderedWireRoutesAndCanonicalEcho()
{
using var communication = new RuntimeCommunicationState();
using var character = new RuntimeCharacterState();
var sent = new List<string>();
var route = new LiveChatCommandRoute(new LiveChatCommandBindings(
command => sent.Add($"client:{command.Command}"),
communication,
communication.Chat,
communication.TurbineChat,
character,
() => 0x50000001u,
text => sent.Add($"talk:{text}"),
(target, text) => sent.Add($"tell:{target}:{text}"),
(channel, text) => sent.Add($"channel:{channel:X8}:{text}"),
(_, _, _, _, text, _) => sent.Add($"turbine:{text}")));
route.Activate();
route.Publish(new SendServerCommandCmd("@server"));
route.Publish(new SendChatCmd(ChatChannelKind.Say, null, "say"));
route.Publish(new SendChatCmd(ChatChannelKind.Tell, "Bob", "secret"));
route.Publish(new SendChatCmd(
ChatChannelKind.Fellowship,
null,
"group"));
route.Publish(new SendRawChannelCmd(0x00000002u, "admin"));
route.Publish(new ExecuteClientCommandCmd(
ClientCommandId.QueryAge,
string.Empty));
Assert.Equal(
[
"talk:@server",
"talk:say",
"tell:Bob:secret",
"channel:00000800:group",
"channel:00000002:admin",
"client:QueryAge",
],
sent);
ChatEntry echo = Assert.Single(communication.Chat.Snapshot());
Assert.Equal(ChatKind.Tell, echo.Kind);
Assert.Equal("Bob", echo.Sender);
Assert.Equal("secret", echo.Text);
route.Dispose();
route.Publish(new SendServerCommandCmd("@stale"));
Assert.Equal(6, sent.Count);
}
}