- Renamed all directories: OpenHarbor.MCP.* → Svrnty.MCP.* - Updated all namespaces in 179 C# files - Renamed 20 .csproj files and 3 .sln files - Updated 193 documentation references - Updated 33 references in main CODEX codebase - Updated Codex.sln with new paths - Build verified: 0 errors Preparing for extraction to standalone repositories. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
141 lines
4.4 KiB
C#
141 lines
4.4 KiB
C#
using Xunit;
|
|
using Moq;
|
|
using Svrnty.MCP.Gateway.Core.Interfaces;
|
|
using Svrnty.MCP.Gateway.Core.Models;
|
|
|
|
namespace Svrnty.MCP.Gateway.Core.Tests.Interfaces;
|
|
|
|
/// <summary>
|
|
/// Unit tests for IHealthChecker interface contract.
|
|
/// Tests health check operations and status tracking.
|
|
/// </summary>
|
|
public class IHealthCheckerTests
|
|
{
|
|
[Fact]
|
|
public async Task CheckHealthAsync_ReturnsHealthStatus()
|
|
{
|
|
// Arrange
|
|
var mockChecker = new Mock<IHealthChecker>();
|
|
var serverConfig = new ServerConfig
|
|
{
|
|
Id = "server-1",
|
|
Name = "Test Server",
|
|
TransportType = "Http",
|
|
BaseUrl = "http://localhost:5000"
|
|
};
|
|
|
|
var expectedStatus = new ServerHealthStatus
|
|
{
|
|
ServerId = "server-1",
|
|
ServerName = "Test Server",
|
|
IsHealthy = true,
|
|
LastCheck = DateTime.UtcNow
|
|
};
|
|
|
|
mockChecker.Setup(c => c.CheckHealthAsync(serverConfig, It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(expectedStatus);
|
|
|
|
// Act
|
|
var result = await mockChecker.Object.CheckHealthAsync(serverConfig);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal("server-1", result.ServerId);
|
|
Assert.True(result.IsHealthy);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CheckHealthAsync_WithUnhealthyServer_ReturnsUnhealthyStatus()
|
|
{
|
|
// Arrange
|
|
var mockChecker = new Mock<IHealthChecker>();
|
|
var serverConfig = new ServerConfig
|
|
{
|
|
Id = "server-2",
|
|
Name = "Unhealthy Server",
|
|
TransportType = "Http",
|
|
BaseUrl = "http://localhost:5001"
|
|
};
|
|
|
|
var expectedStatus = new ServerHealthStatus
|
|
{
|
|
ServerId = "server-2",
|
|
ServerName = "Unhealthy Server",
|
|
IsHealthy = false,
|
|
LastCheck = DateTime.UtcNow,
|
|
ErrorMessage = "Connection timeout"
|
|
};
|
|
|
|
mockChecker.Setup(c => c.CheckHealthAsync(serverConfig, It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(expectedStatus);
|
|
|
|
// Act
|
|
var result = await mockChecker.Object.CheckHealthAsync(serverConfig);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal("server-2", result.ServerId);
|
|
Assert.False(result.IsHealthy);
|
|
Assert.Equal("Connection timeout", result.ErrorMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StartMonitoringAsync_BeginsHealthChecks()
|
|
{
|
|
// Arrange
|
|
var mockChecker = new Mock<IHealthChecker>();
|
|
var serverConfigs = new List<ServerConfig>
|
|
{
|
|
new ServerConfig { Id = "server-1", Name = "Server 1", TransportType = "Http", BaseUrl = "http://localhost:5000" }
|
|
};
|
|
|
|
mockChecker.Setup(c => c.StartMonitoringAsync(serverConfigs, It.IsAny<CancellationToken>()))
|
|
.Returns(Task.CompletedTask);
|
|
|
|
// Act
|
|
await mockChecker.Object.StartMonitoringAsync(serverConfigs);
|
|
|
|
// Assert
|
|
mockChecker.Verify(c => c.StartMonitoringAsync(serverConfigs, It.IsAny<CancellationToken>()), Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StopMonitoringAsync_EndsHealthChecks()
|
|
{
|
|
// Arrange
|
|
var mockChecker = new Mock<IHealthChecker>();
|
|
mockChecker.Setup(c => c.StopMonitoringAsync(It.IsAny<CancellationToken>()))
|
|
.Returns(Task.CompletedTask);
|
|
|
|
// Act
|
|
await mockChecker.Object.StopMonitoringAsync();
|
|
|
|
// Assert
|
|
mockChecker.Verify(c => c.StopMonitoringAsync(It.IsAny<CancellationToken>()), Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetCurrentHealthAsync_ReturnsAllServerHealth()
|
|
{
|
|
// Arrange
|
|
var mockChecker = new Mock<IHealthChecker>();
|
|
var expectedHealth = new List<ServerHealthStatus>
|
|
{
|
|
new ServerHealthStatus { ServerId = "server-1", IsHealthy = true },
|
|
new ServerHealthStatus { ServerId = "server-2", IsHealthy = false }
|
|
};
|
|
|
|
mockChecker.Setup(c => c.GetCurrentHealthAsync(It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(expectedHealth);
|
|
|
|
// Act
|
|
var result = await mockChecker.Object.GetCurrentHealthAsync();
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2, result.Count());
|
|
Assert.Contains(result, s => s.ServerId == "server-1" && s.IsHealthy);
|
|
Assert.Contains(result, s => s.ServerId == "server-2" && !s.IsHealthy);
|
|
}
|
|
}
|