using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Options; using MongoDB.Driver; using Retroactiune.Core.Entities; using Retroactiune.Core.Interfaces; using Retroactiune.Infrastructure; namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures { public class MongoDbFixture : IAsyncDisposable { private readonly IDatabaseSettings _settings; private IMongoDatabase Database { get; } public IMongoCollection FeedbackReceiverCollection => Database.GetCollection(_settings.FeedbackReceiverCollectionName); public IMongoCollection TokensCollection => Database.GetCollection(_settings.TokensCollectionName); public MongoDbFixture(IOptions options) { _settings = options.Value; var client = new MongoClient(_settings.ConnectionString); Database = client.GetDatabase(_settings.DatabaseName); } public async Task DropAsync() { await Task.WhenAll( new List() { Database.DropCollectionAsync(_settings.FeedbackCollectionName), Database.DropCollectionAsync(_settings.FeedbackReceiverCollectionName), Database.DropCollectionAsync(_settings.TokensCollectionName) }); } public async ValueTask DisposeAsync() { await DropAsync(); } } }