- 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>
121 lines
3.3 KiB
C#
121 lines
3.3 KiB
C#
using Xunit;
|
|
using Moq;
|
|
using System.Threading.Tasks;
|
|
using System.Text.Json;
|
|
|
|
namespace Svrnty.MCP.Core.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for IMcpTool interface following TDD approach.
|
|
/// Tests the core abstraction for MCP tools.
|
|
/// </summary>
|
|
public class IMcpToolTests
|
|
{
|
|
[Fact]
|
|
public void IMcpTool_ShouldHaveNameProperty()
|
|
{
|
|
// Arrange - Create a mock implementation
|
|
var mockTool = new Mock<IMcpTool>();
|
|
mockTool.Setup(t => t.Name).Returns("test_tool");
|
|
|
|
// Act
|
|
var name = mockTool.Object.Name;
|
|
|
|
// Assert
|
|
Assert.Equal("test_tool", name);
|
|
}
|
|
|
|
[Fact]
|
|
public void IMcpTool_ShouldHaveDescriptionProperty()
|
|
{
|
|
// Arrange
|
|
var mockTool = new Mock<IMcpTool>();
|
|
mockTool.Setup(t => t.Description).Returns("A test tool");
|
|
|
|
// Act
|
|
var description = mockTool.Object.Description;
|
|
|
|
// Assert
|
|
Assert.Equal("A test tool", description);
|
|
}
|
|
|
|
[Fact]
|
|
public void IMcpTool_ShouldHaveSchemaProperty()
|
|
{
|
|
// Arrange
|
|
var mockTool = new Mock<IMcpTool>();
|
|
var schema = JsonDocument.Parse("""
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"query": { "type": "string" }
|
|
}
|
|
}
|
|
""");
|
|
mockTool.Setup(t => t.Schema).Returns(schema);
|
|
|
|
// Act
|
|
var toolSchema = mockTool.Object.Schema;
|
|
|
|
// Assert
|
|
Assert.NotNull(toolSchema);
|
|
Assert.Equal("object", toolSchema.RootElement.GetProperty("type").GetString());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task IMcpTool_ShouldExecuteAsync()
|
|
{
|
|
// Arrange
|
|
var mockTool = new Mock<IMcpTool>();
|
|
var expectedResult = JsonDocument.Parse("""{"status": "success"}""");
|
|
var arguments = JsonDocument.Parse("""{"query": "test"}""");
|
|
|
|
mockTool.Setup(t => t.ExecuteAsync(It.IsAny<JsonDocument>()))
|
|
.ReturnsAsync(expectedResult);
|
|
|
|
// Act
|
|
var result = await mockTool.Object.ExecuteAsync(arguments);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal("success", result.RootElement.GetProperty("status").GetString());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task IMcpTool_ExecuteAsync_ShouldHandleNullArguments()
|
|
{
|
|
// Arrange
|
|
var mockTool = new Mock<IMcpTool>();
|
|
var expectedResult = JsonDocument.Parse("""{"status": "executed"}""");
|
|
|
|
mockTool.Setup(t => t.ExecuteAsync(null!))
|
|
.ReturnsAsync(expectedResult);
|
|
|
|
// Act
|
|
var result = await mockTool.Object.ExecuteAsync(null!);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task IMcpTool_ExecuteAsync_ShouldReturnJsonResult()
|
|
{
|
|
// Arrange
|
|
var mockTool = new Mock<IMcpTool>();
|
|
var arguments = JsonDocument.Parse("""{"input": "value"}""");
|
|
var expectedResult = JsonDocument.Parse("""{"output": "result"}""");
|
|
|
|
mockTool.Setup(t => t.ExecuteAsync(arguments))
|
|
.ReturnsAsync(expectedResult);
|
|
|
|
// Act
|
|
var result = await mockTool.Object.ExecuteAsync(arguments);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.True(result.RootElement.TryGetProperty("output", out var output));
|
|
Assert.Equal("result", output.GetString());
|
|
}
|
|
}
|