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 | |
parent | Add all projects to sln (diff) | |
download | LibMatrix-bak-2a37322d78c9ce1d27cbc12e24dd918407a931e3.tar.xz |
Update dependencies, some tests, other things dev/event-rewrite
Diffstat (limited to 'Tests')
8 files changed, 227 insertions, 8 deletions
diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/LibMatrix.EventTypes.Abstractions.Tests.csproj b/Tests/LibMatrix.EventTypes.Abstractions.Tests/LibMatrix.EventTypes.Abstractions.Tests.csproj new file mode 100644 index 0000000..d4a45e0 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/LibMatrix.EventTypes.Abstractions.Tests.csproj @@ -0,0 +1,43 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + + <IsPackable>false</IsPackable> + <IsTestProject>true</IsTestProject> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/> + <PackageReference Include="coverlet.collector" Version="6.0.2"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + <PackageReference Include="xunit" Version="2.8.1"/> + <PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + </ItemGroup> + + <ItemGroup> + <Using Include="Xunit"/> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\LibMatrix.EventTypes.Abstractions\LibMatrix.EventTypes.Abstractions.csproj"/> + <ProjectReference Include="..\..\LibMatrix.EventTypes.Spec\LibMatrix.EventTypes.Spec.csproj" /> + </ItemGroup> + + <ItemGroup> + <Content Include="appsettings*.json"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestData\**\*.*"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> + +</Project> 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 diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEvent.json b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEvent.json new file mode 100644 index 0000000..1134a58 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEvent.json @@ -0,0 +1,17 @@ +{ + "content": { + "avatar_url": "mxc://server1/abcdefgh", + "displayname": "User 1", + "is_direct": false, + "membership": "join" + }, + "event_id": "$DLgeeol91D36xqZQvEwRJrOoBKttZ_S66hco8Ci-qb0", + "origin_server_ts": 1717146801732, + "sender": "@user1:server1", + "state_key": "@user1:server1", + "type": "m.room.member", + "unsigned": { + "prev_sender": "@user1:server1", + "replaces_state": "$4QptWS_8YzaZfROeFzOdhoV2wzYPEzQDx0Q6u2UOt8c" + } +} \ No newline at end of file diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEventContent.json b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEventContent.json new file mode 100644 index 0000000..ca328d4 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMembershipEventContent.json @@ -0,0 +1,6 @@ +{ + "avatar_url": "mxc://server1/abcdefgh", + "displayname": "User 1", + "is_direct": false, + "membership": "join" +} \ No newline at end of file diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEvent.json b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEvent.json new file mode 100644 index 0000000..3072114 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEvent.json @@ -0,0 +1,18 @@ +{ + "content": { + "body": "This is a test message", + "format": "org.matrix.custom.html", + "formatted_body": "This is a test message <b>with HTML!</b>", + "m.mentions": { + "user_ids": [ + "@emma:rory.gay" + ] + }, + "msgtype": "m.text" + }, + "event_id": "$qBmS2SyNAA-ODcOZpAd_RRfApzXuMmy0VHsCqnMebzI", + "origin_server_ts": 1717100265714, + "sender": "@user:example.xyz", + "type": "m.room.message", + "unsigned": null +} diff --git a/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEventContent.json b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEventContent.json new file mode 100644 index 0000000..d9c7024 --- /dev/null +++ b/Tests/LibMatrix.EventTypes.Abstractions.Tests/TestData/RoomMessageEventContent.json @@ -0,0 +1,11 @@ +{ + "body": "This is a test message", + "format": "org.matrix.custom.html", + "formatted_body": "This is a test message <b>with HTML!</b>", + "m.mentions": { + "user_ids": [ + "@emma:rory.gay" + ] + }, + "msgtype": "m.text" +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/GlobalUsings.cs b/Tests/LibMatrix.Tests/GlobalUsings.cs deleted file mode 100644 index 8c927eb..0000000 --- a/Tests/LibMatrix.Tests/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj b/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj index d833d8b..085816f 100644 --- a/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj +++ b/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj @@ -10,23 +10,26 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/> - - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23531-01"/> - <PackageReference Include="xunit" Version="2.6.1"/> - <PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="7.0.10"/> - <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/> + <PackageReference Include="coverlet.collector" Version="6.0.2"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="coverlet.collector" Version="3.2.0"> + <PackageReference Include="xunit" Version="2.8.1"/> + <PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> + <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/> + <PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="8.1.0"/> <PackageReference Include="Xunit.SkippableFact" Version="1.4.13"/> </ItemGroup> <ItemGroup> + <Using Include="Xunit"/> + </ItemGroup> + + <ItemGroup> <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/> </ItemGroup> |