Fix tests

This commit is contained in:
Zoe Roux 2023-11-01 17:35:55 +01:00
parent 167e2853f0
commit dfc86e4b96
3 changed files with 8 additions and 8 deletions

View File

@ -18,14 +18,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
using Kyoo.Core;
using Kyoo.Core.Controllers; using Kyoo.Core.Controllers;
using Kyoo.Postgresql; using Kyoo.Postgresql;
using Moq; using Moq;
using Xunit.Abstractions; using Xunit.Abstractions;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Tests.Database namespace Kyoo.Tests.Database
{ {
@ -68,6 +71,10 @@ namespace Kyoo.Tests.Database
user user
}; };
ServiceCollection container = new();
container.AddScoped((_) => _NewContext());
CoreModule.Services = container.BuildServiceProvider();
LibraryManager = new LibraryManager( LibraryManager = new LibraryManager(
libraryItem, libraryItem,
collection, collection,

View File

@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>. // along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -68,7 +68,6 @@ namespace Kyoo.Tests
public sealed class PostgresTestContext : TestContext public sealed class PostgresTestContext : TestContext
{ {
private readonly NpgsqlConnection _connection;
private readonly DbContextOptions<DatabaseContext> _context; private readonly DbContextOptions<DatabaseContext> _context;
public PostgresTestContext(PostgresFixture template, ITestOutputHelper output) public PostgresTestContext(PostgresFixture template, ITestOutputHelper output)
@ -83,11 +82,8 @@ namespace Kyoo.Tests
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
_connection = new NpgsqlConnection(GetConnectionString(database));
_connection.Open();
_context = new DbContextOptionsBuilder<DatabaseContext>() _context = new DbContextOptionsBuilder<DatabaseContext>()
.UseNpgsql(_connection) .UseNpgsql(GetConnectionString(database))
.UseLoggerFactory(LoggerFactory.Create(x => .UseLoggerFactory(LoggerFactory.Create(x =>
{ {
x.ClearProviders(); x.ClearProviders();
@ -111,14 +107,12 @@ namespace Kyoo.Tests
{ {
using DatabaseContext db = New(); using DatabaseContext db = New();
db.Database.EnsureDeleted(); db.Database.EnsureDeleted();
_connection.Close();
} }
public override async ValueTask DisposeAsync() public override async ValueTask DisposeAsync()
{ {
await using DatabaseContext db = New(); await using DatabaseContext db = New();
await db.Database.EnsureDeletedAsync(); await db.Database.EnsureDeletedAsync();
await _connection.CloseAsync();
} }
public override DatabaseContext New() public override DatabaseContext New()