diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-06-03 04:59:40 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-06-03 04:59:40 +0200 |
commit | 2a37322d78c9ce1d27cbc12e24dd918407a931e3 (patch) | |
tree | d3483edae6792bab1f10516b95779367220a2a8d /Tests/LibMatrix.EventTypes.Abstractions.Tests/SerialisationTests.cs | |
parent | Add all projects to sln (diff) | |
download | LibMatrix-dev/event-rewrite.tar.xz |
Update dependencies, some tests, other things dev/event-rewrite
Diffstat (limited to '')
-rw-r--r-- | Tests/LibMatrix.EventTypes.Abstractions.Tests/SerialisationTests.cs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/SerialisationTests.cs b/Tests/LibMatrix.EventTypes.Abstractions.Tests/SerialisationTests.cs new file mode 100644 index 0000000..fe1a575 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/SerialisationTests.cs @@ -0,0 +1,122 @@ +using System.Text.Json; +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec; + +namespace LibMatrix.EventTypes.Abstractions.Tests; + +public class SerialisationTests { + private static readonly Dictionary<string, string> TestData = Directory.GetFiles("TestData").Where(x=>x.EndsWith(".json")).ToDictionary(Path.GetFileNameWithoutExtension, File.ReadAllText); + [Fact] + public void DeserializeEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(TestData["RoomMembershipEvent"]); + Assert.NotNull(evt); + Assert.NotNull(evt.Content); + Assert.NotNull(evt.Content.Membership); + } + + [Fact] + public void DeserialiseEventContent() { + var evt = JsonSerializer.Deserialize<RoomMembershipEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + Assert.NotNull(evt.Membership); + } + + [Fact] + public void DeserializeUnknownEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<BaseMatrixEventContent>>(TestData["RoomMembershipEvent"]); + Assert.NotNull(evt); + Assert.NotNull(evt.Content); + Assert.NotNull(evt.Content["membership"]); + } + + [Fact] + public void DeserializeUnknownEventContent() { + var evt = JsonSerializer.Deserialize<BaseMatrixEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + Assert.NotNull(evt["membership"]); + } + + [Fact] + public void SerializeEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(TestData["RoomMembershipEvent"]); + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("membership", json); + } + + [Fact] + public void SerializeEventContent() { + var evt = JsonSerializer.Deserialize<RoomMembershipEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("membership", json); + } + + [Fact] + public void SerializeUnknownEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<BaseMatrixEventContent>>(TestData["RoomMembershipEvent"]); + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("membership", json); + } + + [Fact] + public void SerializeUnknownEventContent() { + var evt = JsonSerializer.Deserialize<BaseMatrixEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("membership", json); + } + + [Fact] + public void ModifyEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(TestData["RoomMembershipEvent"]); + Assert.NotNull(evt); + Assert.NotNull(evt.Content); + evt.Content.Membership = "meow"; + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("meow", json); + } + + [Fact] + public void ModifyEventContent() { + var evt = JsonSerializer.Deserialize<RoomMembershipEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + evt.Membership = "meow"; + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("meow", json); + } + + [Fact] + public void ModifyUnknownEvent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<BaseMatrixEventContent>>(TestData["RoomMembershipEvent"]); + Assert.NotNull(evt); + evt.Content["membership"] = "meow"; + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("meow", json); + } + + [Fact] + public void ModifyUnknownEventContent() { + var evt = JsonSerializer.Deserialize<BaseMatrixEventContent>(TestData["RoomMembershipEventContent"]); + Assert.NotNull(evt); + evt["membership"] = "meow"; + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("meow", json); + } + + [Fact] + public void SerializeEventWithUnknownContent() { + var evt = JsonSerializer.Deserialize<MatrixEvent<BaseMatrixEventContent>>(TestData["RoomMembershipEvent"]); + Assert.NotNull(evt); + var json = evt.ToJson(); + Assert.NotNull(json); + Assert.Contains("membership", json); + } +} \ No newline at end of file |