Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions ModelContextProtocol.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Project Path="tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj" />
<Project Path="tests/ModelContextProtocol.ConformanceClient/ModelContextProtocol.ConformanceClient.csproj" />
<Project Path="tests/ModelContextProtocol.ConformanceServer/ModelContextProtocol.ConformanceServer.csproj" />
<Project Path="tests/ModelContextProtocol.Netstandard2_0.Tests/ModelContextProtocol.Netstandard2_0.Tests.csproj" />
<Project Path="tests/ModelContextProtocol.TestOAuthServer/ModelContextProtocol.TestOAuthServer.csproj" />
<Project Path="tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj" />
<Project Path="tests/ModelContextProtocol.TestServer/ModelContextProtocol.TestServer.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Please avoid using a separate test project. Ideally this should use the exact same test project, but non-Windows environments should be configured automatically accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use the existing test project with conditional SetTargetFramework on the ModelContextProtocol.Core project reference. On non-Windows platforms, net8.0 tests now use the netstandard2.0 build automatically. See commit 753cc88.

<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>ModelContextProtocol.Tests</RootNamespace>
<!-- https://github.com/dotnet/sdk/issues/51060 -->
<NoWarn>$(NoWarn);NU1903;NU1902</NoWarn>
<!-- Define for conditional TimeProvider support in InMemoryMcpTaskStore -->
<DefineConstants>$(DefineConstants);MCP_TEST_TIME_PROVIDER</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<!-- Without this, tests are currently not showing results until all tests complete
https://xunit.net/docs/getting-started/v3/microsoft-testing-platform
-->
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
</PropertyGroup>

<!-- Include all test source files from the main test project -->
<ItemGroup>
<Compile Include="../ModelContextProtocol.Tests/**/*.cs"
Exclude="../ModelContextProtocol.Tests/bin/**;../ModelContextProtocol.Tests/obj/**" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Common\**\*.cs" />
<!-- Link InMemoryMcpTaskStore.cs for testing with TimeProvider support -->
<Compile Include="..\..\src\ModelContextProtocol.Core\Server\InMemoryMcpTaskStore.cs" Link="Server\InMemoryMcpTaskStore.cs" />
<!-- Include dependencies for the linked InMemoryMcpTaskStore.cs -->
<Compile Include="..\..\src\Common\Experimentals.cs" Link="Experimentals.cs" />
<Compile Include="..\..\src\Common\Polyfills\System\IdHelpers.cs" Link="Polyfills\IdHelpers.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.AI" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="OpenTelemetry" />
<PackageReference Include="OpenTelemetry.Exporter.InMemory" />
<PackageReference Include="Serilog" />
<PackageReference Include="JsonSchema.Net" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Linq.AsyncEnumerable" />
</ItemGroup>

<ItemGroup>
<!-- Force ModelContextProtocol.Core to use netstandard2.0 build -->
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj">
<SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\ModelContextProtocol.TestServer\ModelContextProtocol.TestServer.csproj" />
<ProjectReference Include="..\..\samples\TestServerWithHosting\TestServerWithHosting.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)'))ModelContextProtocol.TestServer\$(Configuration)\$(TargetFramework)\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)'))TestServerWithHosting\$(Configuration)\$(TargetFramework)\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions tests/ModelContextProtocol.Netstandard2_0.Tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ModelContextProtocol.Netstandard2_0.Tests

This test project provides cross-platform testing of the `netstandard2.0` build of `ModelContextProtocol.Core`.

## Purpose

The main test project (`ModelContextProtocol.Tests`) targets multiple frameworks including `net472`, which only runs on Windows. This creates a gap for developers on non-Windows platforms who want to test the `netstandard2.0` build.

This project solves that by:
1. Targeting `net8.0` (stable, cross-platform)
2. Forcing `ModelContextProtocol.Core` to use its `netstandard2.0` build via `SetTargetFramework`
3. Including all test source files from the main test project

## Key Features

- **Cross-platform**: Runs on Windows, Linux, and macOS using the modern .NET runtime
- **netstandard2.0 testing**: Verifies the netstandard2.0 build without requiring .NET Framework or mono
- **Shared tests**: Uses the same test source files as `ModelContextProtocol.Tests` to ensure consistency

## How It Works

The project uses the MSBuild `SetTargetFramework` property on the project reference to force the referenced project to build for a specific target framework:

```xml
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj">
<SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>
```

This allows the test project (targeting `net8.0`) to reference and test the `netstandard2.0` build of `ModelContextProtocol.Core`.

## Running Tests

```bash
# Run all tests
dotnet test tests/ModelContextProtocol.Netstandard2_0.Tests

# Run with filter
dotnet test tests/ModelContextProtocol.Netstandard2_0.Tests --filter '(Execution!=Manual)'
```

## Reference

This pattern is based on the approach used by [googleapis/dotnet-genai](https://github.com/googleapis/dotnet-genai/blob/f0d9a3eb970e91293b806dac49853b68e4ddcdca/Google.GenAI.Tests/Netstandard2_0Tests/Google.GenAI.Netstandard2_0.Tests.csproj).