1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Text . Json ;
4
5
using Xunit ;
5
6
6
7
namespace Microsoft . Extensions . AI ;
@@ -10,15 +11,15 @@ public class AIContentTests
10
11
[ Fact ]
11
12
public void Constructor_PropsDefault ( )
12
13
{
13
- DerivedAIContent c = new ( ) ;
14
+ AIContent c = new ( ) ;
14
15
Assert . Null ( c . RawRepresentation ) ;
15
16
Assert . Null ( c . AdditionalProperties ) ;
16
17
}
17
18
18
19
[ Fact ]
19
20
public void Constructor_PropsRoundtrip ( )
20
21
{
21
- DerivedAIContent c = new ( ) ;
22
+ AIContent c = new ( ) ;
22
23
23
24
Assert . Null ( c . RawRepresentation ) ;
24
25
object raw = new ( ) ;
@@ -31,5 +32,25 @@ public void Constructor_PropsRoundtrip()
31
32
Assert . Same ( props , c . AdditionalProperties ) ;
32
33
}
33
34
34
- private sealed class DerivedAIContent : AIContent ;
35
+ [ Fact ]
36
+ public void Serialization_Roundtrips ( )
37
+ {
38
+ AIContent original = new ( )
39
+ {
40
+ RawRepresentation = new object ( ) ,
41
+ AdditionalProperties = new AdditionalPropertiesDictionary { { "key" , "value" } }
42
+ } ;
43
+
44
+ Assert . NotNull ( original . RawRepresentation ) ;
45
+ Assert . Single ( original . AdditionalProperties ) ;
46
+
47
+ string json = JsonSerializer . Serialize ( original , AIJsonUtilities . DefaultOptions . GetTypeInfo ( typeof ( AIContent ) ) ) ;
48
+ Assert . NotNull ( json ) ;
49
+
50
+ AIContent ? deserialized = ( AIContent ? ) JsonSerializer . Deserialize ( json , AIJsonUtilities . DefaultOptions . GetTypeInfo ( typeof ( AIContent ) ) ) ;
51
+ Assert . NotNull ( deserialized ) ;
52
+ Assert . Null ( deserialized . RawRepresentation ) ;
53
+ Assert . NotNull ( deserialized . AdditionalProperties ) ;
54
+ Assert . Single ( deserialized . AdditionalProperties ) ;
55
+ }
35
56
}
0 commit comments