Add serialization roundtrip tests for all Protocol namespace types (#1289)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
392e47ea29
commit
4cef394ad5
1 changed files with 3222 additions and 475 deletions
|
|
@ -0,0 +1,108 @@
|
|||
using ModelContextProtocol.Protocol;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModelContextProtocol.Tests.Protocol;
|
||||
|
||||
public static class RequestMcpTasksCapabilityTests
|
||||
{
|
||||
[Fact]
|
||||
public static void RequestMcpTasksCapability_SerializationRoundTrip_ToolsOnly()
|
||||
{
|
||||
// Arrange
|
||||
var original = new RequestMcpTasksCapability
|
||||
{
|
||||
Tools = new ToolsMcpTasksCapability
|
||||
{
|
||||
Call = new CallToolMcpTasksCapability()
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<RequestMcpTasksCapability>(json, McpJsonUtilities.DefaultOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.NotNull(deserialized.Tools);
|
||||
Assert.NotNull(deserialized.Tools.Call);
|
||||
Assert.Null(deserialized.Sampling);
|
||||
Assert.Null(deserialized.Elicitation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void RequestMcpTasksCapability_SerializationRoundTrip_SamplingOnly()
|
||||
{
|
||||
// Arrange
|
||||
var original = new RequestMcpTasksCapability
|
||||
{
|
||||
Sampling = new SamplingMcpTasksCapability
|
||||
{
|
||||
CreateMessage = new CreateMessageMcpTasksCapability()
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<RequestMcpTasksCapability>(json, McpJsonUtilities.DefaultOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.Null(deserialized.Tools);
|
||||
Assert.NotNull(deserialized.Sampling);
|
||||
Assert.NotNull(deserialized.Sampling.CreateMessage);
|
||||
Assert.Null(deserialized.Elicitation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void RequestMcpTasksCapability_SerializationRoundTrip_ElicitationOnly()
|
||||
{
|
||||
// Arrange
|
||||
var original = new RequestMcpTasksCapability
|
||||
{
|
||||
Elicitation = new ElicitationMcpTasksCapability
|
||||
{
|
||||
Create = new CreateElicitationMcpTasksCapability()
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions);
|
||||
var deserialized = JsonSerializer.Deserialize<RequestMcpTasksCapability>(json, McpJsonUtilities.DefaultOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.Null(deserialized.Tools);
|
||||
Assert.Null(deserialized.Sampling);
|
||||
Assert.NotNull(deserialized.Elicitation);
|
||||
Assert.NotNull(deserialized.Elicitation.Create);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void RequestMcpTasksCapability_HasCorrectJsonPropertyNames()
|
||||
{
|
||||
var capability = new RequestMcpTasksCapability
|
||||
{
|
||||
Tools = new ToolsMcpTasksCapability
|
||||
{
|
||||
Call = new CallToolMcpTasksCapability()
|
||||
},
|
||||
Sampling = new SamplingMcpTasksCapability
|
||||
{
|
||||
CreateMessage = new CreateMessageMcpTasksCapability()
|
||||
},
|
||||
Elicitation = new ElicitationMcpTasksCapability
|
||||
{
|
||||
Create = new CreateElicitationMcpTasksCapability()
|
||||
}
|
||||
};
|
||||
|
||||
string json = JsonSerializer.Serialize(capability, McpJsonUtilities.DefaultOptions);
|
||||
|
||||
Assert.Contains("\"tools\":", json);
|
||||
Assert.Contains("\"sampling\":", json);
|
||||
Assert.Contains("\"elicitation\":", json);
|
||||
Assert.Contains("\"call\":", json);
|
||||
Assert.Contains("\"createMessage\":", json);
|
||||
Assert.Contains("\"create\":", json);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue