11using System . Text . Json ;
2+ using System . Text . Json . Serialization ;
3+ using System . Text . Json . Serialization . Metadata ;
24
35namespace ModelContextProtocol . Tests ;
46
5- public static class McpJsonUtilitiesTests
7+ public static partial class McpJsonUtilitiesTests
68{
79 [ Fact ]
810 public static void DefaultOptions_IsSingleton ( )
@@ -22,4 +24,27 @@ public static void DefaultOptions_UseReflectionWhenEnabled()
2224
2325 Assert . Equal ( JsonSerializer . IsReflectionEnabledByDefault , options . TryGetTypeInfo ( anonType , out _ ) ) ;
2426 }
27+
28+ [ Fact ]
29+ public static void DefaultOptions_UnknownEnumHandling ( )
30+ {
31+ var options = McpJsonUtilities . DefaultOptions ;
32+
33+ if ( JsonSerializer . IsReflectionEnabledByDefault )
34+ {
35+ Assert . Equal ( "\" A\" " , JsonSerializer . Serialize ( EnumWithoutAnnotation . A , options ) ) ;
36+ Assert . Equal ( "\" A\" " , JsonSerializer . Serialize ( EnumWithAnnotation . A , options ) ) ;
37+ }
38+ else
39+ {
40+ options = new ( options ) { TypeInfoResolver = new DefaultJsonTypeInfoResolver ( ) } ;
41+ Assert . Equal ( "1" , JsonSerializer . Serialize ( EnumWithoutAnnotation . A , options ) ) ;
42+ Assert . Equal ( "\" A\" " , JsonSerializer . Serialize ( EnumWithAnnotation . A , options ) ) ;
43+ }
44+ }
45+
46+ public enum EnumWithoutAnnotation { A = 1 , B = 2 , C = 3 }
47+
48+ [ JsonConverter ( typeof ( JsonStringEnumConverter < EnumWithAnnotation > ) ) ]
49+ public enum EnumWithAnnotation { A = 1 , B = 2 , C = 3 }
2550}
0 commit comments