44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using File.Application.Features.Files.DTOs;
|
|
using File.Application.Features.Files.Handlers;
|
|
using File.Application.Features.Files.Queries;
|
|
using Xunit;
|
|
|
|
namespace BuildFlow.File.Tests;
|
|
|
|
/// <summary>
|
|
/// 批量文件预览路径查询测试。覆盖空引用、外链、对象键转义和输入去重。
|
|
/// </summary>
|
|
public class ResolveFilePreviewPathsQueryHandlerTests
|
|
{
|
|
[Fact]
|
|
public async Task Handle_ShouldResolveDistinctReferencesWithoutStorageAccess()
|
|
{
|
|
var handler = new ResolveFilePreviewPathsQueryHandler();
|
|
|
|
var result = await handler.Handle(new ResolveFilePreviewPathsQuery(
|
|
[
|
|
null,
|
|
"",
|
|
" ",
|
|
"http://cdn.example.com/avatar.png",
|
|
"HTTPS://cdn.example.com/avatar-2.png",
|
|
"avatars/alice one/#photo.png",
|
|
"avatars/alice one/#photo.png",
|
|
]), CancellationToken.None);
|
|
|
|
Assert.Equal(6, result.Count);
|
|
Assert.Contains(new FilePreviewPathDto(null, null), result);
|
|
Assert.Contains(new FilePreviewPathDto("", null), result);
|
|
Assert.Contains(new FilePreviewPathDto(" ", null), result);
|
|
Assert.Contains(new FilePreviewPathDto(
|
|
"http://cdn.example.com/avatar.png",
|
|
"http://cdn.example.com/avatar.png"), result);
|
|
Assert.Contains(new FilePreviewPathDto(
|
|
"HTTPS://cdn.example.com/avatar-2.png",
|
|
"HTTPS://cdn.example.com/avatar-2.png"), result);
|
|
Assert.Contains(new FilePreviewPathDto(
|
|
"avatars/alice one/#photo.png",
|
|
"/api/files/preview?objectKey=avatars%2Falice%20one%2F%23photo.png"), result);
|
|
}
|
|
}
|