Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xBaank committed Aug 14, 2024
1 parent 5d42964 commit c6f3d1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
10 changes: 2 additions & 8 deletions Console/Commands/MainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ public async ValueTask ExecuteAsync(IConsole console)
Utils.ConfigurePlatformDependencies();
await console.Output.WriteLineAsync("Ignore any warnings above this message");
await console.Output.WriteLineAsync("[PortAudio] Initialized corretly");

var upgrader = DeployChanges
.To.SQLiteDatabase(connectionString)
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();

var result = upgrader.PerformUpgrade();
Utils.PerformMigrations(connectionString);
await console.Output.WriteLineAsync("[Db] Initialized corretly");

var top = new Toplevel();

Expand Down
3 changes: 3 additions & 0 deletions Console/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Lazy />
</Weavers>
20 changes: 19 additions & 1 deletion Console/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PortAudioSharp;
using System.Reflection;
using DbUp;
using PortAudioSharp;
using Terminal.Gui;

namespace Console;
Expand All @@ -13,6 +15,22 @@ public static void ConfigurePlatformDependencies()
PortAudio.Initialize();
}

public static void PerformMigrations(string connectionString)
{
var upgrader = DeployChanges
.To.SQLiteDatabase(connectionString)
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();

var result = upgrader.PerformUpgrade();

if (!result.Successful)
{
throw result.Error;
}
}

public static string? ShowInputDialog(string title, string prompt, ColorScheme colorScheme)
{
if (_isShowing)
Expand Down
13 changes: 5 additions & 8 deletions Tests/PlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Console.Database;
using Console.Repositories;
using FluentAssertions;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using YoutubeExplode;

Expand All @@ -13,17 +14,13 @@ 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()
{
var options = CreateInMemoryOptions();
var context = new MyDbContext(options);
var settings = new SettingsRepository(context);
const string connectionString = "Data Source=test.db";
Utils.PerformMigrations(connectionString);
Utils.ConfigurePlatformDependencies();
var connection = new SqliteConnection(connectionString);
var settings = new SettingsRepository(connection);
settings.InitializeAsync().GetAwaiter().GetResult();
_player = new(new YoutubeClient(), settings) { Volume = 0 };
}
Expand Down

0 comments on commit c6f3d1d

Please sign in to comment.