Files
Hua.Todo/test/Hua.Todo.Host.Tests/Attachments/AttachmentModelTests.cs
T
ShaoHua 4fe0b5a963 feat: 完成云同步、语音控制与多平台扩展基础架构搭建
本次提交完成了项目核心基础架构升级:
1. 新增动态API中间件与权限控制系统,支持匿名/鉴权接口分离
2. 搭建云同步服务体系,包含认证、任务同步、安全策略等核心模块
3. 实现语音控制全链路,从STT/意图解析到命令执行
4. 新增任务类型、附件实体与相关仓储接口
5. 重构前端配置与代理规则,统一后端端口为5057
6. 新增多平台测试项目与CI脚本优化
7. 完善项目文档与代码注释规范

移除了旧版迁移文件与冗余代理配置,调整项目结构适配跨平台部署需求。
2026-06-21 03:26:04 +08:00

250 lines
6.9 KiB
C#

using Hua.Todo.Application.Models;
using Hua.Todo.Core.Entities;
using Xunit;
namespace Hua.Todo.Host.Tests.Attachments;
/// <summary>
/// 工单 04 附件与描述数据模型测试。
/// </summary>
public class AttachmentModelTests
{
[Fact]
public void AttachmentEntity_DefaultValues_AreCorrect()
{
var entity = new AttachmentEntity();
Assert.Equal(Guid.Empty, entity.Id);
Assert.Equal(Guid.Empty, entity.TaskId);
Assert.Equal(string.Empty, entity.FileName);
Assert.Equal(string.Empty, entity.FilePath);
Assert.Equal(0L, entity.FileSize);
Assert.Equal(string.Empty, entity.ContentType);
Assert.Equal(AttachmentType.LocalFile, entity.AttachmentType);
Assert.True(entity.CreatedAt <= DateTime.UtcNow);
}
[Fact]
public void AttachmentType_LocalFile_IsZero()
{
Assert.Equal(0, (int)AttachmentType.LocalFile);
}
[Fact]
public void AttachmentType_ExternalLink_IsOne()
{
Assert.Equal(1, (int)AttachmentType.ExternalLink);
}
[Fact]
public void AttachmentEntity_CanBeCreatedWithValues()
{
var id = Guid.NewGuid();
var taskId = Guid.NewGuid();
var entity = new AttachmentEntity
{
Id = id,
TaskId = taskId,
FileName = "需求文档.pdf",
FilePath = "/attachments/42_需求文档.pdf",
FileSize = 204800,
ContentType = "application/pdf",
AttachmentType = AttachmentType.LocalFile,
CreatedAt = new DateTime(2026, 6, 16, 10, 0, 0, DateTimeKind.Utc)
};
Assert.Equal(id, entity.Id);
Assert.Equal(taskId, entity.TaskId);
Assert.Equal("需求文档.pdf", entity.FileName);
Assert.Equal("/attachments/42_需求文档.pdf", entity.FilePath);
Assert.Equal(204800L, entity.FileSize);
Assert.Equal("application/pdf", entity.ContentType);
Assert.Equal(AttachmentType.LocalFile, entity.AttachmentType);
Assert.Equal(new DateTime(2026, 6, 16, 10, 0, 0, DateTimeKind.Utc), entity.CreatedAt);
}
[Fact]
public void AttachmentEntity_ExternalLinkType_HasDefaultFileSizeZero()
{
var entity = new AttachmentEntity
{
AttachmentType = AttachmentType.ExternalLink,
FilePath = "https://example.com/doc"
};
Assert.Equal(0L, entity.FileSize);
Assert.Equal(string.Empty, entity.ContentType);
}
[Fact]
public void AttachmentDto_Properties_AreMapped()
{
var id = Guid.NewGuid();
var taskId = Guid.NewGuid();
var dto = new AttachmentDto
{
Id = id,
TaskId = taskId,
FileName = "test.txt",
FilePath = "/path/to/test.txt",
FileSize = 1024,
ContentType = "text/plain",
AttachmentType = AttachmentType.LocalFile,
CreatedAt = DateTime.UtcNow
};
Assert.Equal(id, dto.Id);
Assert.Equal(taskId, dto.TaskId);
Assert.Equal("test.txt", dto.FileName);
Assert.Equal(1024L, dto.FileSize);
Assert.Equal("text/plain", dto.ContentType);
Assert.Equal(AttachmentType.LocalFile, dto.AttachmentType);
}
[Fact]
public void UploadAttachmentRequest_CanBeCreated()
{
var taskId = Guid.NewGuid();
var request = new UploadAttachmentRequest
{
TaskId = taskId,
FileName = "report.pdf",
Base64Content = "dGVzdA==",
ContentType = "application/pdf"
};
Assert.Equal(taskId, request.TaskId);
Assert.Equal("report.pdf", request.FileName);
Assert.Equal("dGVzdA==", request.Base64Content);
Assert.Equal("application/pdf", request.ContentType);
}
[Fact]
public void AddLinkRequest_CanBeCreated()
{
var taskId = Guid.NewGuid();
var request = new AddLinkRequest
{
TaskId = taskId,
Url = "https://example.com/doc",
FileName = "参考文档"
};
Assert.Equal(taskId, request.TaskId);
Assert.Equal("https://example.com/doc", request.Url);
Assert.Equal("参考文档", request.FileName);
}
[Fact]
public void AddLinkRequest_FileName_CanBeNull()
{
var taskId = Guid.NewGuid();
var request = new AddLinkRequest
{
TaskId = taskId,
Url = "https://example.com/doc"
};
Assert.Null(request.FileName);
}
[Fact]
public void TaskEntity_DefaultDescription_IsNull()
{
var entity = new TaskEntity();
Assert.Null(entity.Description);
}
[Fact]
public void TaskEntity_Description_CanBeSet()
{
var entity = new TaskEntity
{
Description = "这是一个多行描述,用于记录详细说明。"
};
Assert.Equal("这是一个多行描述,用于记录详细说明。", entity.Description);
}
[Fact]
public void TaskEntity_DefaultAttachments_IsEmpty()
{
var entity = new TaskEntity();
Assert.NotNull(entity.Attachments);
Assert.Empty(entity.Attachments);
}
[Fact]
public void TaskDto_IncludesDescription()
{
var dto = new TaskDto
{
Description = "测试描述"
};
Assert.Equal("测试描述", dto.Description);
}
[Fact]
public void TaskDto_IncludesAttachmentCount()
{
var dto = new TaskDto
{
AttachmentCount = 3
};
Assert.Equal(3, dto.AttachmentCount);
}
[Fact]
public void CreateTaskDto_IncludesDescription()
{
var dto = new CreateTaskDto
{
Title = "测试任务",
Description = "描述内容"
};
Assert.Equal("描述内容", dto.Description);
}
[Fact]
public void UpdateTaskDto_Description_IsOptional()
{
var dto = new UpdateTaskDto
{
Id = Guid.NewGuid(),
Title = "更新标题"
// 不传 Description —— 保持原值
};
Assert.Null(dto.Description);
}
[Fact]
public void OpenAttachmentResponse_OpenedProperty()
{
var response = new OpenAttachmentResponse { Opened = true };
Assert.True(response.Opened);
var failed = new OpenAttachmentResponse { Opened = false };
Assert.False(failed.Opened);
}
[Fact]
public void Description_Property_IsDefinedOnTaskEntity()
{
var property = typeof(TaskEntity).GetProperty("Description");
Assert.NotNull(property);
Assert.Equal(typeof(string), property.PropertyType);
}
[Fact]
public void Attachments_Property_IsDefinedOnTaskEntity()
{
var property = typeof(TaskEntity).GetProperty("Attachments");
Assert.NotNull(property);
Assert.Equal(typeof(List<AttachmentEntity>), property.PropertyType);
}
}