Fix enum serialization (#61)

* Fix enum serialization

* Add tests for enum serialization

* Add missing enum serialization configuration.

* Ensure enums serialize as expected using defaults

---------

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
This commit is contained in:
Zae Chao 2025-03-24 20:51:24 +08:00 • committed by GitHub
commit 96ba2fa076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
using ModelContextProtocol.Protocol.Types;
using ModelContextProtocol.Utils.Json;
using System.Text.Json;
namespace ModelContextProtocol.Tests.Protocol;
@ -51,4 +52,41 @@ public static class ProtocolTypeTests
Assert.True(JsonElement.DeepEquals(document.RootElement, tool.InputSchema));
}
[Theory]
[InlineData(Role.User, "\"user\"")]
[InlineData(Role.Assistant, "\"assistant\"")]
public static void SerializeRole_ShouldBeCamelCased(Role role, string expectedValue)
{
var actualValue = JsonSerializer.Serialize(role);
Assert.Equal(expectedValue, actualValue);
}
[Theory]
[InlineData(LoggingLevel.Debug, "\"debug\"")]
[InlineData(LoggingLevel.Info, "\"info\"")]
[InlineData(LoggingLevel.Notice, "\"notice\"")]
[InlineData(LoggingLevel.Warning, "\"warning\"")]
[InlineData(LoggingLevel.Error, "\"error\"")]
[InlineData(LoggingLevel.Critical, "\"critical\"")]
[InlineData(LoggingLevel.Alert, "\"alert\"")]
[InlineData(LoggingLevel.Emergency, "\"emergency\"")]
public static void SerializeLoggingLevel_ShouldBeCamelCased(LoggingLevel level, string expectedValue)
{
var actualValue = JsonSerializer.Serialize(level);
Assert.Equal(expectedValue, actualValue);
}
[Theory]
[InlineData(ContextInclusion.None, "\"none\"")]
[InlineData(ContextInclusion.ThisServer, "\"thisServer\"")]
[InlineData(ContextInclusion.AllServers, "\"allServers\"")]
public static void ContextInclusion_ShouldBeCamelCased(ContextInclusion level, string expectedValue)
{
var actualValue = JsonSerializer.Serialize(level);
Assert.Equal(expectedValue, actualValue);
}
}