@@ -484,6 +484,36 @@ public void SerializeCompoundContent()
484484 Assert . That ( serializedMessage , Does . Contain ( "openai.com/test" ) ) ;
485485 }
486486
487+ [ Test ]
488+ public void CanSerializeChatMessage ( )
489+ {
490+ var text = "Hello, world!" ;
491+ ChatMessage message = new UserChatMessage ( text ) ;
492+ message . Patch . Set ( "$.custom_property"u8 , "custom_property" ) ;
493+
494+ BinaryData serialized = ModelReaderWriter . Write ( message ) ;
495+ using JsonDocument doc = JsonDocument . Parse ( serialized . ToString ( ) ) ;
496+ JsonElement root = doc . RootElement ;
497+
498+ Assert . That ( root , Is . Not . Null ) ;
499+ Assert . That ( root . ValueKind , Is . EqualTo ( JsonValueKind . Object ) ) ;
500+
501+ Assert . That ( root . TryGetProperty ( "content" , out JsonElement contentProperty ) , Is . True ) ;
502+ Assert . That ( contentProperty , Is . Not . Null ) ;
503+ Assert . That ( contentProperty . ValueKind , Is . EqualTo ( JsonValueKind . String ) ) ;
504+ Assert . That ( contentProperty . ToString ( ) , Is . EqualTo ( text ) ) ;
505+
506+ Assert . That ( root . TryGetProperty ( "role" , out JsonElement roleProperty ) , Is . True ) ;
507+ Assert . That ( roleProperty , Is . Not . Null ) ;
508+ Assert . That ( roleProperty . ValueKind , Is . EqualTo ( JsonValueKind . String ) ) ;
509+ Assert . That ( roleProperty . ToString ( ) , Is . EqualTo ( "user" ) ) ;
510+
511+ Assert . That ( root . TryGetProperty ( "custom_property" , out JsonElement customProperty ) , Is . True ) ;
512+ Assert . That ( customProperty , Is . Not . Null ) ;
513+ Assert . That ( customProperty . ValueKind , Is . EqualTo ( JsonValueKind . String ) ) ;
514+ Assert . That ( customProperty . ToString ( ) , Is . EqualTo ( "custom_property" ) ) ;
515+ }
516+
487517 [ Test ]
488518 public void SerializeRefusalMessages ( )
489519 {
0 commit comments