about summary refs log tree commit diff
path: root/ModerationClient/Services/TestRunner.cs
blob: dbacf99d233e659c1c1b32821b0209e9499c9f55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;

namespace ModerationClient.Services;

public class TestRunner(CommandLineConfiguration.TestConfig testConfig, MatrixAuthenticationService mas) : IHostedService {
    public async Task StartAsync(CancellationToken cancellationToken) {
        Console.WriteLine("TestRunner: Starting test runner");
        mas.PropertyChanged += (_, args) => {
            if (args.PropertyName == nameof(MatrixAuthenticationService.IsLoggedIn) && mas.IsLoggedIn) {
                Console.WriteLine("TestRunner: Logged in, starting test");
                _ = Run();
            }
        };
    }

    public async Task StopAsync(CancellationToken cancellationToken) {
        Console.WriteLine("TestRunner: Stopping test runner");
    }

    private async Task Run() {
        var hs = mas.Homeserver!;
        Console.WriteLine("TestRunner: Running test on homeserver " + hs);
        foreach (var mxid in testConfig.Mxids) {
            var room = await hs.CreateRoom(new() {
                Name = mxid,
                Invite = testConfig.Mxids
            });
            
            await room.SendMessageEventAsync(new("test"));

        }
    }
}