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:
parent
1a5732b158
commit
96ba2fa076
1 changed files with 58 additions and 28 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue