1+ using ModelContextProtocol . Protocol ;
2+ using System . Text . Json ;
3+
4+ namespace ModelContextProtocol . Tests . Protocol ;
5+
6+ public static class ImplementationTests
7+ {
8+ [ Fact ]
9+ public static void Implementation_SerializesToJson_WithAllProperties ( )
10+ {
11+ var implementation = new Implementation
12+ {
13+ Name = "test-server" ,
14+ Title = "Test MCP Server" ,
15+ Version = "1.0.0" ,
16+ Icons = new List < Icon >
17+ {
18+ new ( ) { Src = "https://example.com/icon.png" , MimeType = "image/png" , Sizes = "48x48" } ,
19+ new ( ) { Src = "https://example.com/icon.svg" , MimeType = "image/svg+xml" , Sizes = "any" }
20+ } ,
21+ WebsiteUrl = "https://example.com"
22+ } ;
23+
24+ string json = JsonSerializer . Serialize ( implementation ) ;
25+ var result = JsonSerializer . Deserialize < Implementation > ( json ) ;
26+
27+ Assert . Equal ( "test-server" , result ! . Name ) ;
28+ Assert . Equal ( "Test MCP Server" , result . Title ) ;
29+ Assert . Equal ( "1.0.0" , result . Version ) ;
30+ Assert . Equal ( "https://example.com" , result . WebsiteUrl ) ;
31+ Assert . NotNull ( result . Icons ) ;
32+ Assert . Equal ( 2 , result . Icons . Count ) ;
33+ Assert . Equal ( "https://example.com/icon.png" , result . Icons [ 0 ] . Src ) ;
34+ Assert . Equal ( "https://example.com/icon.svg" , result . Icons [ 1 ] . Src ) ;
35+ }
36+
37+ [ Fact ]
38+ public static void Implementation_SerializesToJson_WithoutOptionalProperties ( )
39+ {
40+ var implementation = new Implementation
41+ {
42+ Name = "simple-server" ,
43+ Version = "1.0.0"
44+ } ;
45+
46+ string json = JsonSerializer . Serialize ( implementation ) ;
47+ var result = JsonSerializer . Deserialize < Implementation > ( json ) ;
48+
49+ Assert . Equal ( "simple-server" , result ! . Name ) ;
50+ Assert . Null ( result . Title ) ;
51+ Assert . Equal ( "1.0.0" , result . Version ) ;
52+ Assert . Null ( result . Icons ) ;
53+ Assert . Null ( result . WebsiteUrl ) ;
54+ }
55+
56+ [ Fact ]
57+ public static void Implementation_HasCorrectJsonPropertyNames ( )
58+ {
59+ var implementation = new Implementation
60+ {
61+ Name = "test-server" ,
62+ Title = "Test Server" ,
63+ Version = "1.0.0" ,
64+ Icons = new List < Icon > { new ( ) { Src = "https://example.com/icon.png" } } ,
65+ WebsiteUrl = "https://example.com"
66+ } ;
67+
68+ string json = JsonSerializer . Serialize ( implementation ) ;
69+
70+ Assert . Contains ( "\" name\" :" , json ) ;
71+ Assert . Contains ( "\" title\" :" , json ) ;
72+ Assert . Contains ( "\" version\" :" , json ) ;
73+ Assert . Contains ( "\" icons\" :" , json ) ;
74+ Assert . Contains ( "\" websiteUrl\" :" , json ) ;
75+ }
76+
77+ [ Fact ]
78+ public static void Implementation_EmptyIconsList_SerializesAsEmptyArray ( )
79+ {
80+ var implementation = new Implementation
81+ {
82+ Name = "test-server" ,
83+ Version = "1.0.0" ,
84+ Icons = new List < Icon > ( )
85+ } ;
86+
87+ string json = JsonSerializer . Serialize ( implementation ) ;
88+ var result = JsonSerializer . Deserialize < Implementation > ( json ) ;
89+
90+ Assert . NotNull ( result ! . Icons ) ;
91+ Assert . Empty ( result . Icons ) ;
92+ }
93+ }
0 commit comments