Skip to content

Commit

Permalink
Try to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xBaank committed Aug 13, 2024
1 parent 0a1d3b4 commit dee13b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<PackageReference Include="YoutubeExplodeMusic" Version="6.4.0-music.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Youtube\Suggestions\" />
<InternalsVisibleTo Include="Tests" />
</ItemGroup>
</Project>
7 changes: 5 additions & 2 deletions Console/Database/MyDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Console.Database;

internal class MyDbContext : DbContext
internal class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options)
{
public DbSet<LocalSong> Songs { get; set; }
public DbSet<LocalPlaylist> Playlists { get; set; }
Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions Tests/PlayerTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,10 +13,17 @@ public class PlayerTests : IAsyncDisposable
{
private readonly PlayerController _player;

private DbContextOptions<MyDbContext> CreateInMemoryOptions() =>
new DbContextOptionsBuilder<MyDbContext>()
.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]
Expand Down
1 change: 1 addition & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down

0 comments on commit dee13b8

Please sign in to comment.