📄 tests/Integrations/FaceCamera/FaceDetectionServiceTests/IntegrationTests.cs
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

namespace MMirror.Integrations.FaceCamera.Tests.FaceDetectionServiceTests;

[TestClass]
public sealed class IntegrationTests
{
    [TestMethod]
    public async Task IntegrationTest()
    {
        var host = Host.CreateApplicationBuilder();
        host.Configuration.AddUserSecrets<IntegrationTests>();
        host.Services.AddFaceCameraServices();
        var app = host.Build();
        var faceDetectionService = app.Services.GetRequiredService<FaceDetectionService>();
        var tcs = new TaskCompletionSource<bool>();
        faceDetectionService.FaceDetected += OnFaceDetected;
        var faceDetected = await tcs.Task;
        faceDetected.ShouldBeTrue();

        void OnFaceDetected(bool faceDetected)
        {
            faceDetectionService.FaceDetected -= OnFaceDetected;
            tcs.SetResult(faceDetected);
        }
    }
}