Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 77 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,94 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0.x']
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
dotnet-version: ${{ matrix.dotnet-version }}

- name: Run .NET MCP Server Tests
# Restore packages for all projects first
- name: Restore packages
run: |
dotnet test ./dotnet-mcp/McpServer.Tests/McpServer.Tests.csproj --logger "trx;LogFileName=dotnet-test-results.trx"
echo "Restoring packages for all .NET projects..."
find . -name "*.csproj" -type f | while read proj; do
echo "Restoring: $proj"
dotnet restore "$proj"
done

- name: Run Azure Functions MCP Tests
# Build projects before testing
- name: Build projects
run: |
dotnet test ./azure-functions-mcp/test/azure-functions-mcp.Tests.csproj --logger "trx;LogFileName=azure-functions-test-results.trx"
continue-on-error: true # Some tests are currently failing due to mock setup issues
echo "Building all .NET projects..."
find . -name "*.csproj" -type f | while read proj; do
echo "Building: $proj"
dotnet build "$proj" --no-restore
done

# Discover and run tests for all test projects
- name: Discover and run tests
run: |
echo "Discovering test projects..."
TEST_PROJECTS=$(find . -name "*Tests.csproj" -type f)

if [ -z "$TEST_PROJECTS" ]; then
echo "No test projects found!"
exit 1
fi

echo "Found test projects:"
echo "$TEST_PROJECTS"
echo ""

TEST_FAILED=false

for TEST_PROJECT in $TEST_PROJECTS; do
echo "=============================================="
echo "Running tests for: $TEST_PROJECT"
echo "=============================================="

# Extract project name for logging
PROJECT_NAME=$(basename "$TEST_PROJECT" .csproj)

if dotnet test "$TEST_PROJECT" --no-build --logger "trx;LogFileName=${PROJECT_NAME}-test-results.trx" --verbosity normal; then
echo "βœ… Tests passed for $TEST_PROJECT"
else
echo "❌ Tests failed for $TEST_PROJECT"
if [[ "$TEST_PROJECT" != *"azure-functions-mcp"* ]]; then
# Only fail the build for non-Azure Functions tests
# Azure Functions tests have known Moq issues
TEST_FAILED=true
else
echo "⚠️ Azure Functions tests failed due to known Moq extension method issues"
fi
fi
echo ""
done

if [ "$TEST_FAILED" = true ]; then
echo "❌ Some critical tests failed"
exit 1
else
echo "βœ… All critical tests passed"
fi

- name: Upload Test Results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: "**/*.trx"
name: test-results-${{ matrix.dotnet-version }}
path: "**/*-test-results.trx"

- name: Display Test Summary
if: always()
run: |
echo "=== Test Execution Summary ==="
find . -name "*-test-results.trx" -type f | while read trx_file; do
echo "Test results file: $trx_file"
done
26 changes: 26 additions & 0 deletions mcp-sdk-dotnet.Tests/McpSdkServer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>McpSdkServer.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../mcp-sdk-dotnet/McpSdkServer.csproj" />
</ItemGroup>

</Project>
66 changes: 66 additions & 0 deletions mcp-sdk-dotnet.Tests/PerformanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Diagnostics;
using Xunit;

namespace McpSdkServer.Tests;

/// <summary>
/// Basic performance tests for MCP SDK server
/// These provide a foundation for the future performance monitoring dashboard
/// </summary>
public class PerformanceTests
{
[Fact]
public void BasicOperation_CompletesWithinTimeLimit()
{
// Arrange
var stopwatch = Stopwatch.StartNew();
var testData = new List<string>();

// Act - Simulate basic operations that might be common in MCP servers
for (int i = 0; i < 1000; i++)
{
testData.Add($"test-data-{i}");
}

var result = testData.Count;
stopwatch.Stop();

// Assert - Basic operation should complete quickly
Assert.Equal(1000, result);
Assert.True(stopwatch.ElapsedMilliseconds < 100,
$"Basic operation took {stopwatch.ElapsedMilliseconds}ms, which exceeds 100ms limit");
}

[Fact]
public void MemoryUsage_RemainsReasonable()
{
// Arrange
var initialMemory = GC.GetTotalMemory(false);

// Act - Allocate some memory like an MCP server might
var testObjects = new List<object>();
for (int i = 0; i < 10000; i++)
{
testObjects.Add(new { Id = i, Data = $"test-{i}" });
}

var peakMemory = GC.GetTotalMemory(false);

// Cleanup
testObjects.Clear();
GC.Collect();
GC.WaitForPendingFinalizers();

var finalMemory = GC.GetTotalMemory(true);

// Assert - Memory usage should be reasonable
var memoryUsed = peakMemory - initialMemory;
Assert.True(memoryUsed < 10_000_000, // Less than 10MB for this simple test
$"Memory usage was {memoryUsed / 1024 / 1024}MB, which exceeds 10MB limit");

// Memory should be mostly cleaned up
var memoryLeaked = finalMemory - initialMemory;
Assert.True(memoryLeaked < 1_000_000, // Less than 1MB leaked
$"Memory leak detected: {memoryLeaked / 1024}KB not cleaned up");
}
}
38 changes: 38 additions & 0 deletions mcp-sdk-dotnet.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Xunit;

namespace McpSdkServer.Tests;

public class BasicTests
{
[Fact]
public void Sample_Test_Always_Passes()
{
// This is a basic test to ensure the test project works
Assert.True(true);
}

[Fact]
public void String_Concatenation_Works()
{
// Arrange
var str1 = "Hello";
var str2 = "World";

// Act
var result = str1 + " " + str2;

// Assert
Assert.Equal("Hello World", result);
}

[Fact]
public void DateTime_Now_Is_Valid()
{
// Arrange & Act
var now = DateTime.Now;

// Assert
Assert.True(now > DateTime.MinValue);
Assert.True(now < DateTime.MaxValue);
}
}
Empty file.
Empty file.
Empty file.
Empty file.