Files
Hua.Todo/test/Hua.Todo.Host.Tests/CloudSync/CloudSyncEndpointRegistrationTests.cs
T
ShaoHua 3213d4c718 feat: 完成v1.3.0架构对齐与Web端根路径托管全量开发
- 重构架构:抽离AddCloudSyncServer到扩展类,补全中间层文档对齐
- 修复根路径404与鉴权跳转:新增中间件处理浏览器请求302跳转
- 实现种子数据初始化:添加默认管理员账号自动创建逻辑
- 优化前端代理与构建:新增Vite代理配置与自动构建Target
- 补全测试与文档:新增集成测试,更新开发与部署文档
2026-08-08 07:33:44 +08:00

83 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Hua.Todo.Application.Common;
using Hua.Todo.Application.Repositories;
using Hua.Todo.Application.Services.CloudSync.Services;
using Hua.Todo.HttpApi.AspNetCore.CloudSync;
using Xunit;
namespace Hua.Todo.Host.Tests.CloudSync;
/// <summary>
/// 云同步核心服务 DI 注册集成测试。
/// 模拟 Host 的完整 DI 链路:AddApplicationServices + AddCloudSyncServer,
/// 验证所有关键服务可被正确解析。
/// </summary>
public class CloudSyncEndpointRegistrationTests : IDisposable
{
private readonly SqliteConnection _connection;
private readonly ServiceProvider _provider;
public CloudSyncEndpointRegistrationTests()
{
// 使用共享缓存的 SQLite 内存数据库
_connection = new SqliteConnection("Data Source=CloudSyncRegTests;Mode=Memory;Cache=Shared");
_connection.Open();
var services = new ServiceCollection();
services.AddLogging();
// 模拟 Host 的完整 DI 链路
services.AddApplicationServices("Data Source=CloudSyncRegTests;Mode=Memory;Cache=Shared");
services.AddCloudSyncServer();
_provider = services.BuildServiceProvider();
// 确保数据库表已创建
using var scope = _provider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<TodoDbContext>();
db.Database.EnsureCreated();
}
[Fact]
public void ResolveCloudProbeService_ShouldSucceed()
{
var service = _provider.GetRequiredService<CloudProbeService>();
Assert.NotNull(service);
}
[Fact]
public void ResolveCloudAuthService_ShouldSucceed()
{
var service = _provider.GetRequiredService<CloudAuthService>();
Assert.NotNull(service);
}
[Fact]
public void ResolveCloudTaskSyncService_ShouldSucceed()
{
var service = _provider.GetRequiredService<CloudTaskSyncService>();
Assert.NotNull(service);
}
[Fact]
public void ResolveSecurityPolicyService_ShouldSucceed()
{
var service = _provider.GetRequiredService<SecurityPolicyService>();
Assert.NotNull(service);
}
[Fact]
public void ResolveCloudAdminService_ShouldSucceed()
{
var service = _provider.GetRequiredService<CloudAdminService>();
Assert.NotNull(service);
}
public void Dispose()
{
_provider.Dispose();
_connection.Dispose();
}
}