using BuildFlow.Application.AiModel.DTOs; using BuildFlow.Application.AiModel.Handlers; using BuildFlow.Application.AiModel.Queries; using BuildFlow.Shared.Domain.Errors; using BuildFlow.Shared.Domain.Exceptions; using FluentAssertions; using Xunit; namespace BuildFlow.Rag.Tests; /// /// 刷新远端模型目录处理器测试。 /// 该 Handler 直接调用真实网络(https://models.dev/api.json),无前置分支、无注入点。 /// 单测仅验证「可达即返回非空目录 / 不可达即抛 BusinessException(ErrorCode.Business)」两种实际行为, /// 不假设网络环境,不做断言强耦合。 /// public class RefreshAiModelCatalogQueryHandlerTests { [Fact] public async Task Handle_EitherReturnsCatalogOrThrowsBusinessOnUnreachable() { var handler = new RefreshAiModelCatalogQueryHandler(); try { var result = await handler.Handle(new RefreshAiModelCatalogQuery(), CancellationToken.None); result.Should().NotBeNull(); result.Providers.Should().NotBeNull(); } catch (BusinessException ex) { ex.Code.Should().Be(ErrorCode.Business); } } }