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).
This commit is contained in:
2026-09-09 23:09:43 +02:00
parent 56e06ccd5f
commit b5700614c1
73 changed files with 3718 additions and 3645 deletions
@@ -7,96 +7,97 @@ using Musify.Infrastructure.Services;
using Musify.Infrastructure.Tests.TestSupport;
using Xunit;
namespace Musify.Infrastructure.Tests.Services;
[Collection(InfrastructureCollection.Name)]
public sealed class PlayListPresetSeederTests(InfrastructureTestFixture fixture)
namespace Musify.Infrastructure.Tests.Services
{
private static PlayListConfiguration NewConfiguration(bool overwritePresetPictures) => new()
[Collection(InfrastructureCollection.Name)]
public sealed class PlayListPresetSeederTests(InfrastructureTestFixture fixture)
{
Routes = new PlayListRoutes { ParentFolders = $"PlayLists-{Guid.NewGuid():N}" },
SeedPresetPictures = true,
OverwritePresetPictures = overwritePresetPictures
};
private (PlayListPresetSeeder Seeder, IStorageService Storage) Build(PlayListConfiguration configuration)
{
var services = new ServiceCollection();
services.AddSingleton(configuration);
services.AddSingleton(new ApplicationStorageConfiguration { Bucket = InfrastructureTestFixture.S3Bucket });
services.AddSingleton<IStorageService>(_ => new StorageService(
fixture.CreateDatabase(),
fixture.CreateS3Client(),
NullLogger<StorageService>.Instance,
new InfrastructureStorageConfiguration
{
Address = fixture.S3ServiceUrl,
AccessKey = InfrastructureTestFixture.S3AccessKey,
SecretAccessKey = InfrastructureTestFixture.S3SecretKey,
ForcePathStyle = true,
UseHttp = true,
}));
services.AddSingleton<IPictureService>(new PictureService(NullLogger<PictureService>.Instance));
var provider = services.BuildServiceProvider();
var seeder = new PlayListPresetSeeder(provider.GetRequiredService<IServiceScopeFactory>(), NullLogger<PlayListPresetSeeder>.Instance);
return (seeder, provider.GetRequiredService<IStorageService>());
}
private static async Task RunToCompletionAsync(PlayListPresetSeeder seeder)
{
await seeder.StartAsync(TestContext.Current.CancellationToken);
await (seeder.ExecuteTask ?? Task.CompletedTask);
}
[Fact]
public async Task ExecuteAsync_SeedsAllFourPresetPictures()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
var (seeder, storage) = Build(configuration);
await RunToCompletionAsync(seeder);
var routes = configuration.Routes;
foreach (var key in new[]
{
routes.BuildOriginalPicturePath(routes.PresetOriginalPicture),
routes.PresetSmallPicturePath,
routes.PresetMediumPicturePath,
routes.PresetLargePicturePath
})
private static PlayListConfiguration NewConfiguration(bool overwritePresetPictures) => new()
{
var metadata = await storage.HeadObjectAsync(InfrastructureTestFixture.S3Bucket, key, TestContext.Current.CancellationToken);
Assert.True(metadata is not null, $"expected {key} to have been seeded");
Routes = new PlayListRoutes { ParentFolders = $"PlayLists-{Guid.NewGuid():N}" },
SeedPresetPictures = true,
OverwritePresetPictures = overwritePresetPictures
};
private (PlayListPresetSeeder Seeder, IStorageService Storage) Build(PlayListConfiguration configuration)
{
var services = new ServiceCollection();
services.AddSingleton(configuration);
services.AddSingleton(new ApplicationStorageConfiguration { Bucket = InfrastructureTestFixture.S3Bucket });
services.AddSingleton<IStorageService>(_ => new StorageService(
fixture.CreateDatabase(),
fixture.CreateS3Client(),
NullLogger<StorageService>.Instance,
new InfrastructureStorageConfiguration
{
Address = fixture.S3ServiceUrl,
AccessKey = InfrastructureTestFixture.S3AccessKey,
SecretAccessKey = InfrastructureTestFixture.S3SecretKey,
ForcePathStyle = true,
UseHttp = true,
}));
services.AddSingleton<IPictureService>(new PictureService(NullLogger<PictureService>.Instance));
var provider = services.BuildServiceProvider();
var seeder = new PlayListPresetSeeder(provider.GetRequiredService<IServiceScopeFactory>(), NullLogger<PlayListPresetSeeder>.Instance);
return (seeder, provider.GetRequiredService<IStorageService>());
}
private static async Task RunToCompletionAsync(PlayListPresetSeeder seeder)
{
await seeder.StartAsync(TestContext.Current.CancellationToken);
await (seeder.ExecuteTask ?? Task.CompletedTask);
}
[Fact]
public async Task ExecuteAsync_SeedsAllFourPresetPictures()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
var (seeder, storage) = Build(configuration);
await RunToCompletionAsync(seeder);
var routes = configuration.Routes;
foreach (var key in new[]
{
routes.BuildOriginalPicturePath(routes.PresetOriginalPicture),
routes.PresetSmallPicturePath,
routes.PresetMediumPicturePath,
routes.PresetLargePicturePath
})
{
var metadata = await storage.HeadObjectAsync(InfrastructureTestFixture.S3Bucket, key, TestContext.Current.CancellationToken);
Assert.True(metadata is not null, $"expected {key} to have been seeded");
}
}
[Fact]
public async Task ExecuteAsync_RunTwiceWithoutOverwrite_StaysIdempotent()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
var (firstSeeder, storage) = Build(configuration);
await RunToCompletionAsync(firstSeeder);
var (secondSeeder, _) = Build(configuration);
await RunToCompletionAsync(secondSeeder);
var metadata = await storage.HeadObjectAsync(
InfrastructureTestFixture.S3Bucket, configuration.Routes.PresetSmallPicturePath, TestContext.Current.CancellationToken);
Assert.NotNull(metadata);
}
[Fact]
public async Task ExecuteAsync_SeedPresetPicturesDisabled_UploadsNothing()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
configuration.SeedPresetPictures = false;
var (seeder, storage) = Build(configuration);
await RunToCompletionAsync(seeder);
var metadata = await storage.HeadObjectAsync(
InfrastructureTestFixture.S3Bucket, configuration.Routes.PresetSmallPicturePath, TestContext.Current.CancellationToken);
Assert.Null(metadata);
}
}
[Fact]
public async Task ExecuteAsync_RunTwiceWithoutOverwrite_StaysIdempotent()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
var (firstSeeder, storage) = Build(configuration);
await RunToCompletionAsync(firstSeeder);
var (secondSeeder, _) = Build(configuration);
await RunToCompletionAsync(secondSeeder);
var metadata = await storage.HeadObjectAsync(
InfrastructureTestFixture.S3Bucket, configuration.Routes.PresetSmallPicturePath, TestContext.Current.CancellationToken);
Assert.NotNull(metadata);
}
[Fact]
public async Task ExecuteAsync_SeedPresetPicturesDisabled_UploadsNothing()
{
var configuration = NewConfiguration(overwritePresetPictures: false);
configuration.SeedPresetPictures = false;
var (seeder, storage) = Build(configuration);
await RunToCompletionAsync(seeder);
var metadata = await storage.HeadObjectAsync(
InfrastructureTestFixture.S3Bucket, configuration.Routes.PresetSmallPicturePath, TestContext.Current.CancellationToken);
Assert.Null(metadata);
}
}