diff --git a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs index c68cf414f..476c7e65e 100644 --- a/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs +++ b/back/tests/Kyoo.Tests/Database/RepositoryActivator.cs @@ -18,14 +18,17 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.Linq; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; +using Kyoo.Core; using Kyoo.Core.Controllers; using Kyoo.Postgresql; using Moq; using Xunit.Abstractions; +using Microsoft.Extensions.DependencyInjection; namespace Kyoo.Tests.Database { @@ -68,6 +71,10 @@ public RepositoryActivator(ITestOutputHelper output, PostgresFixture postgres = user }; + ServiceCollection container = new(); + container.AddScoped((_) => _NewContext()); + CoreModule.Services = container.BuildServiceProvider(); + LibraryManager = new LibraryManager( libraryItem, collection, diff --git a/back/tests/Kyoo.Tests/Database/SpecificTests/EpisodeTests.cs b/back/tests/Kyoo.Tests/Database/SpecificTests/EpisodeTests.cs index ef898fcec..d223ece91 100644 --- a/back/tests/Kyoo.Tests/Database/SpecificTests/EpisodeTests.cs +++ b/back/tests/Kyoo.Tests/Database/SpecificTests/EpisodeTests.cs @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/back/tests/Kyoo.Tests/Database/TestContext.cs b/back/tests/Kyoo.Tests/Database/TestContext.cs index 1c5bdca5e..90004e923 100644 --- a/back/tests/Kyoo.Tests/Database/TestContext.cs +++ b/back/tests/Kyoo.Tests/Database/TestContext.cs @@ -68,7 +68,6 @@ public void Dispose() public sealed class PostgresTestContext : TestContext { - private readonly NpgsqlConnection _connection; private readonly DbContextOptions _context; public PostgresTestContext(PostgresFixture template, ITestOutputHelper output) @@ -83,11 +82,8 @@ public PostgresTestContext(PostgresFixture template, ITestOutputHelper output) cmd.ExecuteNonQuery(); } - _connection = new NpgsqlConnection(GetConnectionString(database)); - _connection.Open(); - _context = new DbContextOptionsBuilder() - .UseNpgsql(_connection) + .UseNpgsql(GetConnectionString(database)) .UseLoggerFactory(LoggerFactory.Create(x => { x.ClearProviders(); @@ -111,14 +107,12 @@ public override void Dispose() { using DatabaseContext db = New(); db.Database.EnsureDeleted(); - _connection.Close(); } public override async ValueTask DisposeAsync() { await using DatabaseContext db = New(); await db.Database.EnsureDeletedAsync(); - await _connection.CloseAsync(); } public override DatabaseContext New()