From dee13b870575240e73abdec1dec14e1434543d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bl=C3=A1zquez?= Date: Tue, 13 Aug 2024 13:32:13 +0200 Subject: [PATCH] Try to fix tests --- Console/Console.csproj | 2 +- Console/Database/MyDbContext.cs | 7 +++++-- Tests/PlayerTests.cs | 15 +++++++++++++-- Tests/Tests.csproj | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Console/Console.csproj b/Console/Console.csproj index be5cdf9..46b35a3 100644 --- a/Console/Console.csproj +++ b/Console/Console.csproj @@ -25,6 +25,6 @@ - + \ No newline at end of file diff --git a/Console/Database/MyDbContext.cs b/Console/Database/MyDbContext.cs index 70d93e8..49b2284 100644 --- a/Console/Database/MyDbContext.cs +++ b/Console/Database/MyDbContext.cs @@ -2,7 +2,7 @@ namespace Console.Database; -internal class MyDbContext : DbContext +internal class MyDbContext(DbContextOptions options) : DbContext(options) { public DbSet Songs { get; set; } public DbSet Playlists { get; set; } @@ -11,7 +11,10 @@ internal class MyDbContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Data Source=data.db"); + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlite("Data Source=data.db"); + } } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/Tests/PlayerTests.cs b/Tests/PlayerTests.cs index f520f92..c0f5f5b 100644 --- a/Tests/PlayerTests.cs +++ b/Tests/PlayerTests.cs @@ -1,6 +1,10 @@ +using CliFx.Infrastructure; using Console; using Console.Audio; +using Console.Database; +using Console.Repositories; using FluentAssertions; +using Microsoft.EntityFrameworkCore; using YoutubeExplode; namespace Tests; @@ -9,10 +13,17 @@ public class PlayerTests : IAsyncDisposable { private readonly PlayerController _player; + private DbContextOptions CreateInMemoryOptions() => + new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) // Use a unique database name + .Options; + public PlayerTests() { - Utils.ConfigurePlatformDependencies(); - _player = new(new YoutubeClient()) { Volume = 0 }; + var options = CreateInMemoryOptions(); + var context = new MyDbContext(options); + Utils.ConfigurePlatformDependenciesAsync(new FakeConsole()).GetAwaiter().GetResult(); + _player = new(new YoutubeClient(), new SettingsRepository(context)) { Volume = 0 }; } [Fact] diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index b82919d..8aefa80 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -11,6 +11,7 @@ +