Files
wx-win-agent/tests/node-agent/WxAgent.Core.Tests/WechatAttachmentInputTests.cs
T
rogee edba7d0d38
Build web service image / build (push) Successful in 1m15s
feat: support long text and safe attachment batches
2026-09-30 09:16:36 +08:00

63 lines
2.2 KiB
C#

using WxAgent.Core;
using Xunit;
namespace WxAgent.Core.Tests;
public sealed class WechatAttachmentInputTests
{
[Fact]
public void PrepareFilePathsRejectsOutOfRangeBatchesBeforeAnySend()
{
var single = Assert.Throws<WxAgentException>(() => WechatAttachmentInput.PrepareFilePaths(["one.txt"]));
var tooMany = Assert.Throws<WxAgentException>(() => WechatAttachmentInput.PrepareFilePaths(
Enumerable.Repeat("unused.txt", WechatAttachmentInput.MaxBatchSize + 1).ToArray()));
Assert.Equal(WxAgentErrorCode.InvalidArgument, single.Code);
Assert.Equal(WxAgentErrorCode.InvalidArgument, tooMany.Code);
}
[Fact]
public void PrepareFilePathsValidatesEveryFileBeforeReturningCanonicalPaths()
{
var directory = Directory.CreateTempSubdirectory();
try
{
var first = Path.Combine(directory.FullName, "first.pdf");
var second = Path.Combine(directory.FullName, "second.png");
File.WriteAllText(first, "first");
File.WriteAllText(second, "second");
var paths = WechatAttachmentInput.PrepareFilePaths([first, second]);
Assert.Equal([Path.GetFullPath(first), Path.GetFullPath(second)], paths);
Assert.True(WechatAttachmentInput.IsImagePath(second));
Assert.True(WechatAttachmentInput.IsImagePath("photo.JPEG"));
Assert.False(WechatAttachmentInput.IsImagePath(first));
}
finally
{
directory.Delete(recursive: true);
}
}
[Fact]
public void PrepareFilePathsRejectsASecondMissingFileBeforeSendingTheFirst()
{
var directory = Directory.CreateTempSubdirectory();
try
{
var first = Path.Combine(directory.FullName, "first.pdf");
File.WriteAllText(first, "first");
var exception = Assert.Throws<WxAgentException>(() => WechatAttachmentInput.PrepareFilePaths(
[first, Path.Combine(directory.FullName, "missing.pdf")]));
Assert.Equal(WxAgentErrorCode.InvalidArgument, exception.Code);
}
finally
{
directory.Delete(recursive: true);
}
}
}