Files
Musify/backend/Tests/Musify.Application.Tests/TestSupport/HandlerTestBase.cs
T
Admin b5700614c1 Use block-scoped namespaces in the test suite
Converts all 73 test source files from file-scoped (namespace X;) to
block-scoped (namespace X { ... }) declarations, re-indenting their
contents accordingly. Matches the existing convention already used in
several production files (e.g. Musify.Infrastructure.Configuration,
Musify.Application.Contracts).

Mechanical change only, done with a script, verified with a full
rebuild (0 warnings, 0 errors) and test run (257/257 passing).
2026-09-09 23:09:43 +02:00

35 lines
1.3 KiB
C#

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
namespace Musify.Application.Tests.TestSupport
{
/// <summary>
/// Base class for handler tests: gives every test method its own empty, isolated
/// <see cref="TestDatabase"/> (xUnit creates a new instance of the test class per test method,
/// so there is no state to reset between tests) and a no-op logger factory for handlers that
/// take an <see cref="ILogger{TCategoryName}"/>.
/// </summary>
public abstract class HandlerTestBase : IAsyncLifetime
{
private TestDatabase database = null!;
protected TestDatabase Database => database;
public async ValueTask InitializeAsync() => database = await TestDatabase.CreateAsync();
public ValueTask DisposeAsync() => database.DisposeAsync();
protected static ILogger<T> NoOpLogger<T>() => NullLogger<T>.Instance;
/// <summary>Adds the entities and persists them, so handlers under test see committed data.</summary>
protected async Task SeedAsync(params object[] entities)
{
foreach (var entity in entities)
Database.Add(entity);
await Database.SaveChangesAsync(CancellationToken.None);
}
}
}