a79d8282dc
- 15 Controller-Klassen ersetzen Minimal APIs in Program.cs - Repository Pattern mit Interfaces + Implementierungen (Project, Task, Activity, User) - AuthService verwendet jetzt IUserRepository statt direktem DbContext-Zugriff - SecurityHeadersMiddleware als eigenständige Middleware-Klasse - PathSecurityHelper als gemeinsamer Helper für Pfadvalidierung - DTOs in eigenem Namespace Nexus.Api.DTOs - EF-Entities in Nexus.Api.Data (vorher Nexus.Api.Domain) - Program.cs auf DI-Registrierung + Middleware reduziert - Alle 43 Endpoints unverändert erhalten - Build + 3/3 Tests erfolgreich
79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using Nexus.Api.Services;
|
|
using Nexus.Api.Integrations;
|
|
using Nexus.Api.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Xunit;
|
|
|
|
namespace Nexus.Api.Tests;
|
|
|
|
public class AgentServiceTests
|
|
{
|
|
[Fact]
|
|
public async Task GetAgentsAsync_ReturnsCorrectCount()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json"
|
|
})
|
|
.Build();
|
|
var runtime = new FakeRuntime();
|
|
var service = new AgentService(config, runtime);
|
|
|
|
var agents = await service.GetAgentsAsync(CancellationToken.None);
|
|
Assert.True(agents.Count >= 4, $"Expected at least 4 agents, got {agents.Count}");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetAgentAsync_Iris_ReturnsOrchestrator()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json"
|
|
})
|
|
.Build();
|
|
var runtime = new FakeRuntime();
|
|
var service = new AgentService(config, runtime);
|
|
|
|
var agent = await service.GetAgentAsync("iris", CancellationToken.None);
|
|
Assert.NotNull(agent);
|
|
Assert.Equal("Orchestrator", agent.Role);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetAgentAsync_Unknown_ReturnsNull()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json"
|
|
})
|
|
.Build();
|
|
var runtime = new FakeRuntime();
|
|
var service = new AgentService(config, runtime);
|
|
|
|
var agent = await service.GetAgentAsync("nonexistent", CancellationToken.None);
|
|
Assert.Null(agent);
|
|
}
|
|
}
|
|
|
|
public sealed class FakeRuntime : IAgentRuntime
|
|
{
|
|
public string Name => "FakeRuntime";
|
|
|
|
public Task<AgentRuntimeStatus> GetStatusAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(new AgentRuntimeStatus(
|
|
Runtime: "OpenClaw",
|
|
Status: OperationalStatus.Online,
|
|
Latency: TimeSpan.FromMilliseconds(10),
|
|
Detail: "Fake runtime for testing"));
|
|
|
|
public Task<AgentChatResult> ChatAsync(string message, string conversationId, string agentId, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(new AgentChatResult(
|
|
Runtime: "OpenClaw",
|
|
AgentId: agentId,
|
|
ConversationId: conversationId,
|
|
Content: "Echo: " + message));
|
|
}
|