44 lines
2.2 KiB
C#
44 lines
2.2 KiB
C#
using WxAgent.Core;
|
|
using Xunit;
|
|
|
|
namespace WxAgent.Core.Tests;
|
|
|
|
public sealed class WechatSendConfirmationTests
|
|
{
|
|
[Fact]
|
|
public void RequiresFreshMatchingTypeAndExactReplyText()
|
|
{
|
|
var baseline = new Dictionary<string, int> { ["old"] = 1 };
|
|
var current = new Dictionary<string, int> { ["old"] = 1, ["new"] = 1 };
|
|
var reply = new ChatMessageSnapshot("reply", "new", 0, ChatMessageType.Quote);
|
|
Assert.True(WechatSendConfirmation.Matches(reply, baseline, current, ChatMessageType.Quote, "reply"));
|
|
Assert.False(WechatSendConfirmation.Matches(reply with { Fingerprint = "old" }, baseline, current, ChatMessageType.Quote, "reply"));
|
|
Assert.False(WechatSendConfirmation.Matches(reply with { Type = ChatMessageType.Text }, baseline, current, ChatMessageType.Quote, "reply"));
|
|
Assert.False(WechatSendConfirmation.Matches(reply with { Text = "another reply" }, baseline, current, ChatMessageType.Quote, "reply"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("report.txt", true)]
|
|
[InlineData("文件\nreport.txt\n1 KB", true)]
|
|
[InlineData("文件\r\nreport.txt\r\n1 KB", true)]
|
|
[InlineData("other-report.txt", false)]
|
|
[InlineData("report.txt.backup", false)]
|
|
public void FileConfirmationRequiresExactFilenameLine(string text, bool expected)
|
|
{
|
|
var message = new ChatMessageSnapshot(text, "new", 0, ChatMessageType.File);
|
|
Assert.Equal(expected, WechatSendConfirmation.Matches(message, new Dictionary<string, int>(),
|
|
new Dictionary<string, int> { ["new"] = 1 }, ChatMessageType.File, "report.txt"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ImageConfirmationRejectsOtherTypesAndOldRows()
|
|
{
|
|
var message = new ChatMessageSnapshot("[图片]", "new", 0, ChatMessageType.Image);
|
|
var empty = new Dictionary<string, int>();
|
|
var current = new Dictionary<string, int> { ["new"] = 1 };
|
|
Assert.True(WechatSendConfirmation.Matches(message, empty, current, ChatMessageType.Image, null));
|
|
Assert.False(WechatSendConfirmation.Matches(message, current, current, ChatMessageType.Image, null));
|
|
Assert.False(WechatSendConfirmation.Matches(message with { Type = ChatMessageType.Text }, empty, current, ChatMessageType.Image, null));
|
|
}
|
|
}
|