about summary refs log tree commit diff
path: root/Tests/LibMatrix.Tests/Abstractions
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-06 18:29:15 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-06 18:29:15 +0200
commite5591eef3850a9796cc87386128651a828b70697 (patch)
tree7e501ec749229a3d96838265289266bb6f6ce208 /Tests/LibMatrix.Tests/Abstractions
parentUnit tests, small refactors (diff)
downloadLibMatrix-e5591eef3850a9796cc87386128651a828b70697.tar.xz
Small refactors
Diffstat (limited to '')
-rw-r--r--Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs42
-rw-r--r--Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs34
2 files changed, 54 insertions, 22 deletions
diff --git a/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs b/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs
index abd3e99..e23d4f4 100644
--- a/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs
+++ b/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs
@@ -6,7 +6,7 @@ namespace LibMatrix.Tests.Abstractions;
 
 public static class HomeserverAbstraction {
     public static async Task<AuthenticatedHomeserverGeneric> GetHomeserver() {
-        var rhs = new RemoteHomeServer("https://matrixunittests.rory.gay");
+        var rhs = await RemoteHomeServer.Create("https://matrixunittests.rory.gay");
         // string username = Guid.NewGuid().ToString();
         // string password = Guid.NewGuid().ToString();
         string username = "@f1a2d2d6-1924-421b-91d0-893b347b2a49:matrixunittests.rory.gay";
@@ -25,15 +25,15 @@ public static class HomeserverAbstraction {
 
         var hs = await reg.GetAuthenticatedHomeserver("https://matrixunittests.rory.gay");
 
-        var rooms = await hs.GetJoinedRooms();
+        //var rooms = await hs.GetJoinedRooms();
 
-        var disbandRoomTasks = rooms.Select(async room => {
-            // await room.DisbandRoomAsync();
-            await room.LeaveAsync();
-            await room.ForgetAsync();
-            return room;
-        }).ToList();
-        await Task.WhenAll(disbandRoomTasks);
+        // var disbandRoomTasks = rooms.Select(async room => {
+        //     // await room.DisbandRoomAsync();
+        //     await room.LeaveAsync();
+        //     await room.ForgetAsync();
+        //     return room;
+        // }).ToList();
+        // await Task.WhenAll(disbandRoomTasks);
 
         // foreach (var room in rooms) {
         //     // await room.DisbandRoomAsync();
@@ -45,28 +45,28 @@ public static class HomeserverAbstraction {
     }
 
     public static async Task<AuthenticatedHomeserverGeneric> GetRandomHomeserver() {
-        var rhs = new RemoteHomeServer("https://matrixunittests.rory.gay");
+        var rhs = await RemoteHomeServer.Create("https://matrixunittests.rory.gay");
         LoginResponse reg = await rhs.RegisterAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Unit tests!");
         var hs = await reg.GetAuthenticatedHomeserver("https://matrixunittests.rory.gay");
 
-        var rooms = await hs.GetJoinedRooms();
-
-        var disbandRoomTasks = rooms.Select(async room => {
-            // await room.DisbandRoomAsync();
-            await room.LeaveAsync();
-            await room.ForgetAsync();
-            return room;
-        }).ToList();
-        await Task.WhenAll(disbandRoomTasks);
+        // var rooms = await hs.GetJoinedRooms();
+        //
+        // var disbandRoomTasks = rooms.Select(async room => {
+        //     // await room.DisbandRoomAsync();
+        //     await room.LeaveAsync();
+        //     await room.ForgetAsync();
+        //     return room;
+        // }).ToList();
+        // await Task.WhenAll(disbandRoomTasks);
 
         return hs;
     }
 
     public static async IAsyncEnumerable<AuthenticatedHomeserverGeneric> GetRandomHomeservers(int count = 1) {
-        var createSpaceTasks = Enumerable
+        var createRandomUserTasks = Enumerable
             .Range(0, count)
             .Select(_ => GetRandomHomeserver()).ToAsyncEnumerable();
-        await foreach (var hs in createSpaceTasks) {
+        await foreach (var hs in createRandomUserTasks) {
             yield return hs;
         }
     }
diff --git a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
index 44c35da..76b8c8c 100644
--- a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
+++ b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
@@ -8,11 +8,43 @@ namespace LibMatrix.Tests.Abstractions;
 
 public static class RoomAbstraction {
     public static async Task<GenericRoom> GetTestRoom(AuthenticatedHomeserverGeneric hs) {
-        var testRoom = await hs.CreateRoom(new CreateRoomRequest() {
+        var crq = new CreateRoomRequest() {
             Name = "LibMatrix Test Room",
             // Visibility = CreateRoomVisibility.Public,
             RoomAliasName = Guid.NewGuid().ToString()
+        };
+        crq.InitialState ??= new();
+        crq.InitialState.Add(new StateEvent() {
+            Type = "m.room.topic",
+            StateKey = "",
+            TypedContent = new RoomTopicEventContent() {
+                Topic = "LibMatrix Test Room " + DateTime.Now.ToString("O")
+            }
+        });
+        crq.InitialState.Add(new StateEvent() {
+            Type = "m.room.name",
+            StateKey = "",
+            TypedContent = new RoomNameEventContent() {
+                Name = "LibMatrix Test Room " + DateTime.Now.ToString("O")
+            }
+        });
+        crq.InitialState.Add(new StateEvent() {
+            Type = "m.room.avatar",
+            StateKey = "",
+            TypedContent = new RoomAvatarEventContent() {
+                Url = "mxc://conduit.rory.gay/r9KiT0f9eQbv8pv4RxwBZFuzhfKjGWHx"
+            }
+        });
+        crq.InitialState.Add(new StateEvent() {
+            Type = "m.room.aliases",
+            StateKey = "",
+            TypedContent = new RoomAliasEventContent() {
+                Aliases = Enumerable
+                    .Range(0, 100)
+                    .Select(_ => $"#{Guid.NewGuid()}:matrixunittests.rory.gay").ToList()
+            }
         });
+        var testRoom = await hs.CreateRoom(crq);
 
         await testRoom.SendStateEventAsync("gay.rory.libmatrix.unit_test_room", new());