Skip to content

Commit

Permalink
Handle event sources in DynamicSerializer (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwpedro authored Nov 12, 2024
1 parent 2424860 commit 86b3039
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Fauna.Test/Serialization/Serializers/DynamicSerializer.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,26 @@ public void RoundTripMappedClass()
string serialized = Helpers.Serialize(Serializer.Dynamic, _ctx, deserialized);
Assert.AreEqual("{\"@ref\":{\"id\":\"123\",\"coll\":{\"@mod\":\"MappedColl\"}}}", serialized);
}

[Test]
public void RoundTripEventSource()
{
const string wire = """{"@stream":"test123="}""";
object? deserialized = Helpers.Deserialize(Serializer.Dynamic, _ctx, wire);
switch (deserialized)
{
case EventSource e:
Assert.AreEqual("test123=", e.Token);
Assert.IsNull(e.Options.Cursor);
Assert.IsNull(e.Options.StartTs);
Assert.IsNull(e.Options.PageSize);
break;
default:
Assert.Fail($"result is type: {deserialized?.GetType()}");
break;
}

// We do not support encoding EventSources
Assert.Throws<NotImplementedException>(() => Helpers.Serialize(Serializer.Dynamic, _ctx, deserialized));
}
}
1 change: 1 addition & 0 deletions Fauna/Serialization/DynamicSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private DynamicSerializer()
TokenType.Module => reader.GetModule(),
TokenType.Bytes => reader.GetBytes(),
TokenType.Null => null,
TokenType.EventSource => reader.GetEventSource(),
_ => throw new SerializationException(
$"Unexpected token while deserializing: {reader.CurrentTokenType}"),
};
Expand Down

0 comments on commit 86b3039

Please sign in to comment.