File tree Expand file tree Collapse file tree
tests/ModelContextProtocol.Tests/Protocol Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class ElicitationCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void ElicitationCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new ElicitationCapability
12+ {
13+ Form = new FormElicitationCapability ( ) ,
14+ Url = new UrlElicitationCapability ( )
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < ElicitationCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Form ) ;
22+ Assert . NotNull ( deserialized . Url ) ;
23+ }
24+
25+ [ Fact ]
26+ public static void ElicitationCapability_SerializationRoundTrip_WithMinimalProperties ( )
27+ {
28+ var original = new ElicitationCapability ( ) ;
29+
30+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
31+ var deserialized = JsonSerializer . Deserialize < ElicitationCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
32+
33+ Assert . NotNull ( deserialized ) ;
34+ // The custom converter defaults Form to non-null when both Form and Url are null for backward compatibility
35+ Assert . NotNull ( deserialized . Form ) ;
36+ Assert . Null ( deserialized . Url ) ;
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+ using System . Text . Json . Nodes ;
4+
5+ namespace ModelContextProtocol . Tests . Protocol ;
6+
7+ public static class PromptListChangedNotificationParamsTests
8+ {
9+ [ Fact ]
10+ public static void PromptListChangedNotificationParams_SerializationRoundTrip_PreservesAllProperties ( )
11+ {
12+ var original = new PromptListChangedNotificationParams
13+ {
14+ Meta = new JsonObject { [ "key" ] = "value" }
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < PromptListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Meta ) ;
22+ }
23+
24+ [ Fact ]
25+ public static void PromptListChangedNotificationParams_SerializationRoundTrip_WithMinimalProperties ( )
26+ {
27+ var original = new PromptListChangedNotificationParams ( ) ;
28+
29+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
30+ var deserialized = JsonSerializer . Deserialize < PromptListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
31+
32+ Assert . NotNull ( deserialized ) ;
33+ Assert . Null ( deserialized . Meta ) ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class PromptsCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void PromptsCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new PromptsCapability
12+ {
13+ ListChanged = true
14+ } ;
15+
16+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
17+ var deserialized = JsonSerializer . Deserialize < PromptsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
18+
19+ Assert . NotNull ( deserialized ) ;
20+ Assert . True ( deserialized . ListChanged ) ;
21+ }
22+
23+ [ Fact ]
24+ public static void PromptsCapability_SerializationRoundTrip_WithMinimalProperties ( )
25+ {
26+ var original = new PromptsCapability ( ) ;
27+
28+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
29+ var deserialized = JsonSerializer . Deserialize < PromptsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
30+
31+ Assert . NotNull ( deserialized ) ;
32+ Assert . Null ( deserialized . ListChanged ) ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+ using System . Text . Json . Nodes ;
4+
5+ namespace ModelContextProtocol . Tests . Protocol ;
6+
7+ public static class ResourceListChangedNotificationParamsTests
8+ {
9+ [ Fact ]
10+ public static void ResourceListChangedNotificationParams_SerializationRoundTrip_PreservesAllProperties ( )
11+ {
12+ var original = new ResourceListChangedNotificationParams
13+ {
14+ Meta = new JsonObject { [ "key" ] = "value" }
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < ResourceListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Meta ) ;
22+ }
23+
24+ [ Fact ]
25+ public static void ResourceListChangedNotificationParams_SerializationRoundTrip_WithMinimalProperties ( )
26+ {
27+ var original = new ResourceListChangedNotificationParams ( ) ;
28+
29+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
30+ var deserialized = JsonSerializer . Deserialize < ResourceListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
31+
32+ Assert . NotNull ( deserialized ) ;
33+ Assert . Null ( deserialized . Meta ) ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class ResourcesCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void ResourcesCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new ResourcesCapability
12+ {
13+ Subscribe = true ,
14+ ListChanged = true
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < ResourcesCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . True ( deserialized . Subscribe ) ;
22+ Assert . True ( deserialized . ListChanged ) ;
23+ }
24+
25+ [ Fact ]
26+ public static void ResourcesCapability_SerializationRoundTrip_WithMinimalProperties ( )
27+ {
28+ var original = new ResourcesCapability ( ) ;
29+
30+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
31+ var deserialized = JsonSerializer . Deserialize < ResourcesCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
32+
33+ Assert . NotNull ( deserialized ) ;
34+ Assert . Null ( deserialized . Subscribe ) ;
35+ Assert . Null ( deserialized . ListChanged ) ;
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class RootsCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void RootsCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new RootsCapability
12+ {
13+ ListChanged = true
14+ } ;
15+
16+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
17+ var deserialized = JsonSerializer . Deserialize < RootsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
18+
19+ Assert . NotNull ( deserialized ) ;
20+ Assert . True ( deserialized . ListChanged ) ;
21+ }
22+
23+ [ Fact ]
24+ public static void RootsCapability_SerializationRoundTrip_WithMinimalProperties ( )
25+ {
26+ var original = new RootsCapability ( ) ;
27+
28+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
29+ var deserialized = JsonSerializer . Deserialize < RootsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
30+
31+ Assert . NotNull ( deserialized ) ;
32+ Assert . Null ( deserialized . ListChanged ) ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+ using System . Text . Json . Nodes ;
4+
5+ namespace ModelContextProtocol . Tests . Protocol ;
6+
7+ public static class RootsListChangedNotificationParamsTests
8+ {
9+ [ Fact ]
10+ public static void RootsListChangedNotificationParams_SerializationRoundTrip_PreservesAllProperties ( )
11+ {
12+ var original = new RootsListChangedNotificationParams
13+ {
14+ Meta = new JsonObject { [ "key" ] = "value" }
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < RootsListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Meta ) ;
22+ }
23+
24+ [ Fact ]
25+ public static void RootsListChangedNotificationParams_SerializationRoundTrip_WithMinimalProperties ( )
26+ {
27+ var original = new RootsListChangedNotificationParams ( ) ;
28+
29+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
30+ var deserialized = JsonSerializer . Deserialize < RootsListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
31+
32+ Assert . NotNull ( deserialized ) ;
33+ Assert . Null ( deserialized . Meta ) ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class SamplingCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void SamplingCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new SamplingCapability
12+ {
13+ Context = new SamplingContextCapability ( ) ,
14+ Tools = new SamplingToolsCapability ( )
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < SamplingCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Context ) ;
22+ Assert . NotNull ( deserialized . Tools ) ;
23+ }
24+
25+ [ Fact ]
26+ public static void SamplingCapability_SerializationRoundTrip_WithMinimalProperties ( )
27+ {
28+ var original = new SamplingCapability ( ) ;
29+
30+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
31+ var deserialized = JsonSerializer . Deserialize < SamplingCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
32+
33+ Assert . NotNull ( deserialized ) ;
34+ Assert . Null ( deserialized . Context ) ;
35+ Assert . Null ( deserialized . Tools ) ;
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+ using System . Text . Json . Nodes ;
4+
5+ namespace ModelContextProtocol . Tests . Protocol ;
6+
7+ public static class ToolListChangedNotificationParamsTests
8+ {
9+ [ Fact ]
10+ public static void ToolListChangedNotificationParams_SerializationRoundTrip_PreservesAllProperties ( )
11+ {
12+ var original = new ToolListChangedNotificationParams
13+ {
14+ Meta = new JsonObject { [ "key" ] = "value" }
15+ } ;
16+
17+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
18+ var deserialized = JsonSerializer . Deserialize < ToolListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
19+
20+ Assert . NotNull ( deserialized ) ;
21+ Assert . NotNull ( deserialized . Meta ) ;
22+ }
23+
24+ [ Fact ]
25+ public static void ToolListChangedNotificationParams_SerializationRoundTrip_WithMinimalProperties ( )
26+ {
27+ var original = new ToolListChangedNotificationParams ( ) ;
28+
29+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
30+ var deserialized = JsonSerializer . Deserialize < ToolListChangedNotificationParams > ( json , McpJsonUtilities . DefaultOptions ) ;
31+
32+ Assert . NotNull ( deserialized ) ;
33+ Assert . Null ( deserialized . Meta ) ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class ToolsCapabilityTests
7+ {
8+ [ Fact ]
9+ public static void ToolsCapability_SerializationRoundTrip_PreservesAllProperties ( )
10+ {
11+ var original = new ToolsCapability
12+ {
13+ ListChanged = true
14+ } ;
15+
16+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
17+ var deserialized = JsonSerializer . Deserialize < ToolsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
18+
19+ Assert . NotNull ( deserialized ) ;
20+ Assert . True ( deserialized . ListChanged ) ;
21+ }
22+
23+ [ Fact ]
24+ public static void ToolsCapability_SerializationRoundTrip_WithMinimalProperties ( )
25+ {
26+ var original = new ToolsCapability ( ) ;
27+
28+ string json = JsonSerializer . Serialize ( original , McpJsonUtilities . DefaultOptions ) ;
29+ var deserialized = JsonSerializer . Deserialize < ToolsCapability > ( json , McpJsonUtilities . DefaultOptions ) ;
30+
31+ Assert . NotNull ( deserialized ) ;
32+ Assert . Null ( deserialized . ListChanged ) ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments