using Mongo2Go;
using MongoDB.Driver;
using Xunit;

namespace StellaOps.Scanner.Storage.Tests;

public sealed class ScannerMongoFixture : IAsyncLifetime
{
    public MongoDbRunner Runner { get; private set; } = null!;
    public IMongoClient Client { get; private set; } = null!;
    public IMongoDatabase Database { get; private set; } = null!;

    public Task InitializeAsync()
    {
        Runner = MongoDbRunner.Start(singleNodeReplSet: true);
        Client = new MongoClient(Runner.ConnectionString);
        Database = Client.GetDatabase($"scanner-tests-{Guid.NewGuid():N}");
        return Task.CompletedTask;
    }

    public Task DisposeAsync()
    {
        Runner.Dispose();
        return Task.CompletedTask;
    }
}
