|  | 
| 1 | 1 | using System.Text.Json; | 
| 2 | 2 | using System.Text.Json.Serialization; | 
| 3 | 3 | using System.Text.Json.Serialization.Metadata; | 
|  | 4 | +using ModelContextProtocol.Protocol; | 
| 4 | 5 | 
 | 
| 5 | 6 | namespace ModelContextProtocol.Tests; | 
| 6 | 7 | 
 | 
| @@ -43,6 +44,38 @@ public static void DefaultOptions_UnknownEnumHandling() | 
| 43 | 44 |         } | 
| 44 | 45 |     } | 
| 45 | 46 | 
 | 
|  | 47 | +    [Fact] | 
|  | 48 | +    public static void DefaultOptions_CanSerializeIEnumerableOfContentBlock() | 
|  | 49 | +    { | 
|  | 50 | +        var options = McpJsonUtilities.DefaultOptions; | 
|  | 51 | +         | 
|  | 52 | +        // Create an IEnumerable<ContentBlock> with different content types | 
|  | 53 | +        IEnumerable<ContentBlock> contentBlocks = new List<ContentBlock> | 
|  | 54 | +        { | 
|  | 55 | +            new TextContentBlock { Text = "Hello World" }, | 
|  | 56 | +            new TextContentBlock { Text = "Test message" } | 
|  | 57 | +        }; | 
|  | 58 | + | 
|  | 59 | +        // Should not throw NotSupportedException | 
|  | 60 | +        string json = JsonSerializer.Serialize(contentBlocks, options); | 
|  | 61 | +         | 
|  | 62 | +        Assert.NotNull(json); | 
|  | 63 | +        Assert.Contains("Hello World", json); | 
|  | 64 | +        Assert.Contains("Test message", json); | 
|  | 65 | +        Assert.Contains("\"type\":\"text\"", json); | 
|  | 66 | +         | 
|  | 67 | +        // Should also be able to deserialize back | 
|  | 68 | +        var deserialized = JsonSerializer.Deserialize<IEnumerable<ContentBlock>>(json, options); | 
|  | 69 | +        Assert.NotNull(deserialized); | 
|  | 70 | +        var deserializedList = deserialized.ToList(); | 
|  | 71 | +        Assert.Equal(2, deserializedList.Count); | 
|  | 72 | +        Assert.All(deserializedList, cb => Assert.Equal("text", cb.Type)); | 
|  | 73 | +         | 
|  | 74 | +        var textBlocks = deserializedList.Cast<TextContentBlock>().ToArray(); | 
|  | 75 | +        Assert.Equal("Hello World", textBlocks[0].Text); | 
|  | 76 | +        Assert.Equal("Test message", textBlocks[1].Text); | 
|  | 77 | +    } | 
|  | 78 | + | 
| 46 | 79 |     public enum EnumWithoutAnnotation { A = 1, B = 2, C = 3 } | 
| 47 | 80 | 
 | 
| 48 | 81 |     [JsonConverter(typeof(JsonStringEnumConverter<EnumWithAnnotation>))] | 
|  | 
0 commit comments