diff options
Diffstat (limited to 'Tests/LibMatrix.Tests')
-rw-r--r-- | Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs | 12 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs | 29 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Config.cs | 9 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/DataTests/WhoAmITests.cs | 2 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Fixtures/TestFixture.cs | 6 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/GlobalUsings.cs | 2 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/LibMatrix.Tests.csproj | 16 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Tests/AuthTests.cs | 2 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Tests/ResolverTest.cs | 3 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Tests/RoomEventTests.cs | 7 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Tests/RoomTests.cs | 20 | ||||
-rw-r--r-- | Tests/LibMatrix.Tests/Tests/TestCleanup.cs | 2 |
12 files changed, 49 insertions, 61 deletions
diff --git a/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs b/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs index 8a976a7..c9727d6 100644 --- a/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs +++ b/Tests/LibMatrix.Tests/Abstractions/HomeserverAbstraction.cs @@ -9,8 +9,8 @@ public static class HomeserverAbstraction { 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"; - string password = "d6d782d6-8bc9-4fac-9cd8-78e101b4298b"; + var username = "@f1a2d2d6-1924-421b-91d0-893b347b2a49:matrixunittests.rory.gay"; + var password = "d6d782d6-8bc9-4fac-9cd8-78e101b4298b"; LoginResponse reg; try { reg = await rhs.LoginAsync(username, password); @@ -46,7 +46,7 @@ public static class HomeserverAbstraction { public static async Task<AuthenticatedHomeserverGeneric> GetRandomHomeserver() { var rhs = await RemoteHomeserver.Create("https://matrixunittests.rory.gay"); - LoginResponse reg = await rhs.RegisterAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Unit tests!"); + var 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(); @@ -66,8 +66,6 @@ public static class HomeserverAbstraction { var createRandomUserTasks = Enumerable .Range(0, count) .Select(_ => GetRandomHomeserver()).ToAsyncEnumerable(); - await foreach (var hs in createRandomUserTasks) { - yield return hs; - } + await foreach (var hs in createRandomUserTasks) yield return hs; } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs index 0cbcf75..2a380fc 100644 --- a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs +++ b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs @@ -14,7 +14,7 @@ public static class RoomAbstraction { // Visibility = CreateRoomVisibility.Public, RoomAliasName = Guid.NewGuid().ToString() }; - crq.InitialState ??= new(); + crq.InitialState ??= new List<StateEvent>(); crq.InitialState.Add(new StateEvent() { Type = "m.room.topic", StateKey = "", @@ -47,7 +47,7 @@ public static class RoomAbstraction { }); var testRoom = await hs.CreateRoom(crq); - await testRoom.SendStateEventAsync("gay.rory.libmatrix.unit_test_room", new()); + await testRoom.SendStateEventAsync("gay.rory.libmatrix.unit_test_room", new object()); return testRoom; } @@ -55,16 +55,15 @@ public static class RoomAbstraction { private static SemaphoreSlim _spaceSemaphore = null!; public static async Task<SpaceRoom> GetTestSpace(AuthenticatedHomeserverGeneric hs, int roomCount = 100, bool addSpaces = false, int spaceSizeReduction = 10) { - _spaceSemaphore ??= new(roomCount / spaceSizeReduction, roomCount / spaceSizeReduction); + _spaceSemaphore ??= new SemaphoreSlim(roomCount / spaceSizeReduction, roomCount / spaceSizeReduction); var crq = new CreateRoomRequest() { Name = $"LibMatrix Test Space ({roomCount} children)", // Visibility = CreateRoomVisibility.Public, RoomAliasName = Guid.NewGuid().ToString(), - InitialState = new() + InitialState = new List<StateEvent>() }; crq.CreationContentBaseType.Type = "m.space"; - var createRoomTasks = Enumerable.Range(0, roomCount) .Select(_ => hs.CreateRoom(new CreateRoomRequest() { Name = $"LibMatrix Test Room {Guid.NewGuid()}", @@ -72,38 +71,36 @@ public static class RoomAbstraction { RoomAliasName = Guid.NewGuid().ToString() })).ToAsyncEnumerable(); - await foreach (var room in createRoomTasks) { - crq.InitialState.Add(new() { + await foreach (var room in createRoomTasks) + crq.InitialState.Add(new StateEvent { Type = "m.space.child", StateKey = room.RoomId, TypedContent = new SpaceChildEventContent() { - Via = new() { + Via = new List<string> { room.RoomId.Split(":")[1] } } }); - } - if (addSpaces) { - for (int i = 0; i < roomCount; i++) { + if (addSpaces) + for (var i = 0; i < roomCount; i++) { var space = await GetTestSpace(hs, roomCount - spaceSizeReduction, true, spaceSizeReduction); - crq.InitialState.Add(new() { + crq.InitialState.Add(new StateEvent { Type = "m.space.child", StateKey = space.RoomId, TypedContent = new SpaceChildEventContent() { - Via = new() { + Via = new List<string> { space.RoomId.Split(":")[1] } } }); } - } var testSpace = (await hs.CreateRoom(crq)).AsSpace; - await testSpace.SendStateEventAsync("gay.rory.libmatrix.unit_test_room", new()); + await testSpace.SendStateEventAsync("gay.rory.libmatrix.unit_test_room", new object()); // _spaceSemaphore.Release(); return testSpace; } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Config.cs b/Tests/LibMatrix.Tests/Config.cs index fb4ef02..ddbf705 100644 --- a/Tests/LibMatrix.Tests/Config.cs +++ b/Tests/LibMatrix.Tests/Config.cs @@ -8,10 +8,11 @@ public class Config { public string? TestRoomAlias { get; set; } = Environment.GetEnvironmentVariable("LIBMATRIX_TEST_ROOM_ALIAS") ?? null; public Dictionary<string, string> ExpectedHomeserverMappings { get; set; } = new() { - {"matrix.org", "https://matrix-client.matrix.org"}, - {"rory.gay", "https://matrix.rory.gay"} + { "matrix.org", "https://matrix-client.matrix.org" }, + { "rory.gay", "https://matrix.rory.gay" } }; + public Dictionary<string, string> ExpectedAliasMappings { get; set; } = new() { - {"#libmatrix:rory.gay", "!tuiLEoMqNOQezxILzt:rory.gay"} + { "#libmatrix:rory.gay", "!tuiLEoMqNOQezxILzt:rory.gay" } }; -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/DataTests/WhoAmITests.cs b/Tests/LibMatrix.Tests/DataTests/WhoAmITests.cs index 056cd3c..e1da3d5 100644 --- a/Tests/LibMatrix.Tests/DataTests/WhoAmITests.cs +++ b/Tests/LibMatrix.Tests/DataTests/WhoAmITests.cs @@ -7,4 +7,4 @@ public static class WhoAmITests { if (!isAppservice) Assert.NotNull(obj.DeviceId); } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Fixtures/TestFixture.cs b/Tests/LibMatrix.Tests/Fixtures/TestFixture.cs index ef49b3e..35c8704 100644 --- a/Tests/LibMatrix.Tests/Fixtures/TestFixture.cs +++ b/Tests/LibMatrix.Tests/Fixtures/TestFixture.cs @@ -11,8 +11,8 @@ public class TestFixture : TestBedFixture { protected override void AddServices(IServiceCollection services, IConfiguration? configuration) { services.AddSingleton<TieredStorageService>(x => new TieredStorageService( - cacheStorageProvider: null, - dataStorageProvider: null + null, + null ) ); @@ -34,4 +34,4 @@ public class TestFixture : TestBedFixture { protected override IEnumerable<TestAppSettings> GetTestAppSettings() { yield return new TestAppSettings { Filename = "appsettings.json", IsOptional = true }; } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/GlobalUsings.cs b/Tests/LibMatrix.Tests/GlobalUsings.cs index c802f44..8c927eb 100644 --- a/Tests/LibMatrix.Tests/GlobalUsings.cs +++ b/Tests/LibMatrix.Tests/GlobalUsings.cs @@ -1 +1 @@ -global using Xunit; +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 3f7bc87..d833d8b 100644 --- a/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj +++ b/Tests/LibMatrix.Tests/LibMatrix.Tests.csproj @@ -10,11 +10,11 @@ </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="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"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> @@ -23,11 +23,11 @@ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Xunit.SkippableFact" Version="1.4.13" /> + <PackageReference Include="Xunit.SkippableFact" Version="1.4.13"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj" /> + <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/> </ItemGroup> <ItemGroup> @@ -35,5 +35,5 @@ <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> - + </Project> diff --git a/Tests/LibMatrix.Tests/Tests/AuthTests.cs b/Tests/LibMatrix.Tests/Tests/AuthTests.cs index 5476b84..67ba8eb 100644 --- a/Tests/LibMatrix.Tests/Tests/AuthTests.cs +++ b/Tests/LibMatrix.Tests/Tests/AuthTests.cs @@ -68,4 +68,4 @@ public class AuthTests : TestBed<TestFixture> { Assert.NotNull(hs.AccessToken); await hs.Logout(); } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Tests/ResolverTest.cs b/Tests/LibMatrix.Tests/Tests/ResolverTest.cs index 804ad6c..700aa96 100644 --- a/Tests/LibMatrix.Tests/Tests/ResolverTest.cs +++ b/Tests/LibMatrix.Tests/Tests/ResolverTest.cs @@ -10,6 +10,7 @@ public class ResolverTest : TestBed<TestFixture> { private readonly HomeserverResolverService _resolver; private readonly Config _config; private readonly HomeserverProviderService _provider; + public ResolverTest(ITestOutputHelper testOutputHelper, TestFixture fixture) : base(testOutputHelper, fixture) { _fixture = fixture; _resolver = _fixture.GetService<HomeserverResolverService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverResolverService)}"); @@ -51,4 +52,4 @@ public class ResolverTest : TestBed<TestFixture> { var profile = await hs.GetProfileAsync("@alice-is-:matrix.org"); Assert.NotNull(profile); } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs b/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs index 060e6f2..932909f 100644 --- a/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs +++ b/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs @@ -20,9 +20,7 @@ public class RoomEventTests : TestBed<TestFixture> { _provider = _fixture.GetService<HomeserverProviderService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverProviderService)}"); } - private async Task<AuthenticatedHomeserverGeneric> GetHomeserver() { - return await HomeserverAbstraction.GetHomeserver(); - } + private async Task<AuthenticatedHomeserverGeneric> GetHomeserver() => await HomeserverAbstraction.GetHomeserver(); [Fact] public async Task GetNameAsync() { @@ -153,5 +151,4 @@ public class RoomEventTests : TestBed<TestFixture> { Assert.NotNull(power.Users); // Assert.NotNull(power.Events); } - -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Tests/RoomTests.cs b/Tests/LibMatrix.Tests/Tests/RoomTests.cs index bec8d18..4f7ac17 100644 --- a/Tests/LibMatrix.Tests/Tests/RoomTests.cs +++ b/Tests/LibMatrix.Tests/Tests/RoomTests.cs @@ -23,9 +23,7 @@ public class RoomTests : TestBed<TestFixture> { _provider = _fixture.GetService<HomeserverProviderService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverProviderService)}"); } - private async Task<AuthenticatedHomeserverGeneric> GetHomeserver() { - return await HomeserverAbstraction.GetHomeserver(); - } + private async Task<AuthenticatedHomeserverGeneric> GetHomeserver() => await HomeserverAbstraction.GetHomeserver(); [Fact] public async Task GetJoinedRoomsAsync() { @@ -43,7 +41,6 @@ public class RoomTests : TestBed<TestFixture> { await hs.Logout(); } - [Fact] public async Task GetMembersAsync() { Assert.True(StateEvent.KnownStateEventTypes is { Count: > 0 }, "StateEvent.KnownStateEventTypes is empty!"); @@ -54,7 +51,7 @@ public class RoomTests : TestBed<TestFixture> { Assert.NotNull(room); var members = room.GetMembersEnumerableAsync(); Assert.NotNull(members); - bool hitMembers = false; + var hitMembers = false; await foreach (var member in members) { Assert.NotNull(member); Assert.NotNull(member.StateKey); @@ -211,7 +208,7 @@ public class RoomTests : TestBed<TestFixture> { Assert.NotNull(room); var res = await room.SendFileAsync("test.txt", new MemoryStream(Encoding.UTF8.GetBytes("This test was written by Emma [it/its], member of the Rory& system." + - "\nIf you are reading this on matrix, it means the unit test for uploading a file works!"))); + "\nIf you are reading this on matrix, it means the unit test for uploading a file works!"))); Assert.NotNull(res); Assert.NotNull(res.EventId); } @@ -223,10 +220,8 @@ public class RoomTests : TestBed<TestFixture> { Assert.NotNull(space); var children = space.GetChildrenAsync(); Assert.NotNull(children); - int found = 0; - await foreach (var room in children) { - found++; - } + var found = 0; + await foreach (var room in children) found++; Assert.Equal(2, found); } @@ -240,15 +235,14 @@ public class RoomTests : TestBed<TestFixture> { // var expectedCount = 1; var tasks = new List<Task>(); - await foreach (var otherUser in otherUsers) { + await foreach (var otherUser in otherUsers) tasks.Add(Task.Run(async () => { await room.InviteUserAsync(otherUser.UserId); await otherUser.GetRoom(room.RoomId).JoinAsync(); })); - } await Task.WhenAll(tasks); var states = await room.GetMembersListAsync(false); Assert.Equal(16, states.Count); } -} +} \ No newline at end of file diff --git a/Tests/LibMatrix.Tests/Tests/TestCleanup.cs b/Tests/LibMatrix.Tests/Tests/TestCleanup.cs index d056345..7fc7c64 100644 --- a/Tests/LibMatrix.Tests/Tests/TestCleanup.cs +++ b/Tests/LibMatrix.Tests/Tests/TestCleanup.cs @@ -71,4 +71,4 @@ public class TestCleanup : TestBed<TestFixture> { Assert.NotNull(hs); await hs.Logout(); } -} +} \ No newline at end of file |