using System; using System.Threading.Tasks; using Kyoo.Controllers; namespace Kyoo.Tests { public class RepositoryActivator : IDisposable, IAsyncDisposable { public TestContext Context { get; } public ILibraryManager LibraryManager { get; } private readonly DatabaseContext _database; public RepositoryActivator(PostgresFixture postgres = null) { Context = postgres == null ? new SqLiteTestContext() : new PostgresTestContext(postgres); _database = Context.New(); ProviderRepository provider = new(_database); LibraryRepository library = new(_database, provider); CollectionRepository collection = new(_database); GenreRepository genre = new(_database); StudioRepository studio = new(_database); PeopleRepository people = new(_database, provider, new Lazy(() => LibraryManager.ShowRepository)); ShowRepository show = new(_database, studio, people, genre, provider); SeasonRepository season = new(_database, provider); LibraryItemRepository libraryItem = new(_database, new Lazy(() => LibraryManager.LibraryRepository), new Lazy(() => LibraryManager.ShowRepository), new Lazy(() => LibraryManager.CollectionRepository)); TrackRepository track = new(_database); EpisodeRepository episode = new(_database, provider, track); LibraryManager = new LibraryManager(new IBaseRepository[] { provider, library, libraryItem, collection, show, season, episode, track, people, studio, genre }); } public void Dispose() { _database.Dispose(); Context.Dispose(); GC.SuppressFinalize(this); } public async ValueTask DisposeAsync() { await _database.DisposeAsync(); await Context.DisposeAsync(); } } }