63 lines
2.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|