about summary refs log tree commit diff
path: root/Tests
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
commit5affd9f061e75f6575a2fe6715f9e8757cfe87e8 (patch)
tree13ea35ce981094a960746777a16dff8815c45e55 /Tests
parentTemp state (diff)
downloadLibMatrix-bak-5affd9f061e75f6575a2fe6715f9e8757cfe87e8.tar.xz
Cleanup
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs3
-rw-r--r--Tests/LibMatrix.Tests/Tests/RoomEventTests.cs7
-rw-r--r--Tests/LibMatrix.Tests/Tests/RoomTests.cs1
-rw-r--r--Tests/LibMatrix.Tests/Tests/TestCleanup.cs6
-rw-r--r--Tests/TestDataGenerator/Bot/DataFetcher.cs27
-rw-r--r--Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs2
-rw-r--r--Tests/TestDataGenerator/Program.cs8
7 files changed, 18 insertions, 36 deletions
diff --git a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
index 76b8c8c..0cbcf75 100644
--- a/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
+++ b/Tests/LibMatrix.Tests/Abstractions/RoomAbstraction.cs
@@ -1,5 +1,6 @@
 using ArcaneLibs.Extensions;
 using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.EventTypes.Spec.State.RoomInfo;
 using LibMatrix.Homeservers;
 using LibMatrix.Responses;
 using LibMatrix.RoomTypes;
@@ -61,7 +62,7 @@ public static class RoomAbstraction {
             RoomAliasName = Guid.NewGuid().ToString(),
             InitialState = new()
         };
-        crq._creationContentBaseType.Type = "m.space";
+        crq.CreationContentBaseType.Type = "m.space";
 
 
         var createRoomTasks = Enumerable.Range(0, roomCount)
diff --git a/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs b/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs
index 6828087..060e6f2 100644
--- a/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs
+++ b/Tests/LibMatrix.Tests/Tests/RoomEventTests.cs
@@ -1,6 +1,3 @@
-using System.Text;
-using ArcaneLibs.Extensions;
-using LibMatrix.EventTypes.Spec.State;
 using LibMatrix.Homeservers;
 using LibMatrix.Services;
 using LibMatrix.Tests.Abstractions;
@@ -88,8 +85,8 @@ public class RoomEventTests : TestBed<TestFixture> {
         Assert.NotNull(room);
         var rule = await room.GetJoinRuleAsync();
         Assert.NotNull(rule);
-        Assert.NotNull(rule.JoinRule);
-        Assert.NotEmpty(rule.JoinRule);
+        Assert.NotNull(rule.JoinRuleValue);
+        Assert.NotEmpty(rule.JoinRuleValue);
     }
 
     [Fact]
diff --git a/Tests/LibMatrix.Tests/Tests/RoomTests.cs b/Tests/LibMatrix.Tests/Tests/RoomTests.cs
index 3a11de9..913e044 100644
--- a/Tests/LibMatrix.Tests/Tests/RoomTests.cs
+++ b/Tests/LibMatrix.Tests/Tests/RoomTests.cs
@@ -1,5 +1,4 @@
 using System.Text;
-using ArcaneLibs.Extensions;
 using LibMatrix.EventTypes.Spec.State;
 using LibMatrix.Homeservers;
 using LibMatrix.Responses;
diff --git a/Tests/LibMatrix.Tests/Tests/TestCleanup.cs b/Tests/LibMatrix.Tests/Tests/TestCleanup.cs
index 8fb7443..d056345 100644
--- a/Tests/LibMatrix.Tests/Tests/TestCleanup.cs
+++ b/Tests/LibMatrix.Tests/Tests/TestCleanup.cs
@@ -1,9 +1,7 @@
 using System.Diagnostics;
-using ArcaneLibs.Extensions;
 using LibMatrix.Helpers;
 using LibMatrix.Services;
 using LibMatrix.Tests.Abstractions;
-using LibMatrix.Tests.DataTests;
 using LibMatrix.Tests.Fixtures;
 using Microsoft.Extensions.Logging;
 using Xunit.Abstractions;
@@ -12,14 +10,14 @@ using Xunit.Microsoft.DependencyInjection.Abstracts;
 namespace LibMatrix.Tests.Tests;
 
 public class TestCleanup : TestBed<TestFixture> {
-    private readonly TestFixture _fixture;
+    // private readonly TestFixture _fixture;
     private readonly HomeserverResolverService _resolver;
     private readonly Config _config;
     private readonly HomeserverProviderService _provider;
     private readonly ILogger<TestCleanup> _logger;
 
     public TestCleanup(ITestOutputHelper testOutputHelper, TestFixture fixture) : base(testOutputHelper, fixture) {
-        _fixture = fixture;
+        // _fixture = fixture;
         _resolver = _fixture.GetService<HomeserverResolverService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverResolverService)}");
         _config = _fixture.GetService<Config>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(Config)}");
         _provider = _fixture.GetService<HomeserverProviderService>(_testOutputHelper) ?? throw new InvalidOperationException($"Failed to get {nameof(HomeserverProviderService)}");
diff --git a/Tests/TestDataGenerator/Bot/DataFetcher.cs b/Tests/TestDataGenerator/Bot/DataFetcher.cs
index b1f8402..5e8c1a1 100644
--- a/Tests/TestDataGenerator/Bot/DataFetcher.cs
+++ b/Tests/TestDataGenerator/Bot/DataFetcher.cs
@@ -1,25 +1,17 @@
-using System.Text;
-using System.Threading.Channels;
 using ArcaneLibs.Extensions;
 using LibMatrix.EventTypes.Spec;
-using LibMatrix.EventTypes.Spec.State;
-using LibMatrix.Helpers;
 using LibMatrix.Homeservers;
-using LibMatrix.Interfaces;
 using LibMatrix.RoomTypes;
-using LibMatrix.Services;
-using LibMatrix.Tests;
 using LibMatrix.Utilities.Bot;
-using LibMatrix.Utilities.Bot.Interfaces;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 
-namespace PluralContactBotPoC.Bot;
+#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
 
-public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher> logger, LibMatrixBotConfiguration botConfiguration,
-    // DataFetcherConfiguration configuration,
-    HomeserverResolverService hsResolver) : IHostedService {
-    private Task _listenerTask;
+namespace TestDataGenerator.Bot;
+
+public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher> logger, LibMatrixBotConfiguration botConfiguration) : IHostedService {
+    private Task? _listenerTask;
 
     private GenericRoom? _logRoom;
 
@@ -32,7 +24,7 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
 
     private async Task Run(CancellationToken cancellationToken) {
         Directory.GetFiles("bot_data/cache").ToList().ForEach(File.Delete);
-        _logRoom = hs.GetRoom(botConfiguration.LogRoom);
+        _logRoom = hs.GetRoom(botConfiguration.LogRoom!);
 
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Test data collector started!"));
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching rooms..."));
@@ -42,16 +34,14 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
 
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching room data..."));
 
-        Config cfg = new Config();
-
         var roomAliasTasks = rooms.Select(room => room.GetCanonicalAliasAsync()).ToAsyncEnumerable();
         List<Task<(string, string)>> aliasResolutionTasks = new();
         await foreach (var @event in roomAliasTasks) {
             if (@event?.Alias != null) {
                 await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched room alias {(@event).Alias}!"));
-                aliasResolutionTasks.Add(Task<(string, string)>.Run(async () => {
+                aliasResolutionTasks.Add(Task.Run(async () => {
                     var alias = await hs.ResolveRoomAliasAsync(@event.Alias);
-                    return (@event.Alias, @alias.RoomId);
+                    return (@event.Alias, alias.RoomId);
                 }, cancellationToken));
             }
         }
@@ -65,5 +55,6 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
     /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
     public async Task StopAsync(CancellationToken cancellationToken) {
         logger.LogInformation("Shutting down bot!");
+        _listenerTask?.Dispose();
     }
 }
diff --git a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs b/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
index 06df0eb..a586d05 100644
--- a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
+++ b/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
@@ -1,6 +1,6 @@
 using Microsoft.Extensions.Configuration;
 
-namespace PluralContactBotPoC.Bot;
+namespace TestDataGenerator.Bot;
 
 public class DataFetcherConfiguration {
     public DataFetcherConfiguration(IConfiguration config) => config.GetRequiredSection("DataFetcher").Bind(this);
diff --git a/Tests/TestDataGenerator/Program.cs b/Tests/TestDataGenerator/Program.cs
index 18ba61e..5d36215 100644
--- a/Tests/TestDataGenerator/Program.cs
+++ b/Tests/TestDataGenerator/Program.cs
@@ -1,19 +1,15 @@
 // See https://aka.ms/new-console-template for more information
 
-using System.Text.Json;
-using System.Text.Json.Serialization;
-using ArcaneLibs.Extensions;
 using LibMatrix.Services;
 using LibMatrix.Utilities.Bot;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
-using PluralContactBotPoC;
-using PluralContactBotPoC.Bot;
+using TestDataGenerator.Bot;
 
 Console.WriteLine("Hello, World!");
 
 var host = Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => {
-    services.AddScoped<TieredStorageService>(x =>
+    services.AddScoped<TieredStorageService>(_ =>
         new TieredStorageService(
             cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
             dataStorageProvider: new FileStorageProvider("bot_data/data/")