-
Notifications
You must be signed in to change notification settings - Fork 699
Add cross-platform netstandard2.0 test coverage #1235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/add-net8-test-project
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4
−1
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5ad652
Initial plan
Copilot 38dcf26
Add netstandard2.0 test project targeting net8.0
Copilot eea465d
Add README for netstandard2.0 test project
Copilot 753cc88
Use conditional SetTargetFramework in existing test project instead o…
Copilot db11c07
Remove platform-specific DefaultTestTargetFrameworks and apply SetTar…
Copilot 259aee5
Revert "Remove platform-specific DefaultTestTargetFrameworks"
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...odelContextProtocol.Netstandard2_0.Tests/ModelContextProtocol.Netstandard2_0.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
SetTargetFrameworkon the ModelContextProtocol.Core project reference. On non-Windows platforms, net8.0 tests now use the netstandard2.0 build automatically. See commit 753cc88.