using MongoDB.Bson;
using Mongo2Go;
using Xunit;
using MongoDB.Driver;

namespace StellaOps.Feedser.Testing;

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

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

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