From b57949a6bcab3611ae48bdfb70e7bb0c5e6e580c Mon Sep 17 00:00:00 2001 From: XShine555 Date: Wed, 9 Sep 2026 21:53:00 +0200 Subject: [PATCH] Fix test bad practices and tighten weak assertions - StorageServiceTests: replace out-param + manual dispose with IAsyncLifetime - PictureServiceTests: Assert.True bound checks -> Assert.InRange - CreateAlbumCommandHandlerTests: assert the specific NotFound error type instead of just IsError, matching what the test name promises - CreateAlbumRequestValidatorTests: replace a boundary Theory that computed its expected result inline with explicit Facts against the real AlbumReleaseYear constants - Remove unused using directives across a handful of production and test files found during the review Full suite verified green: 250/250 tests passing, 0 build warnings. --- .../ApplicationDependencyInjection.cs | 1 - .../Responses/TrackApplicationResponse.cs | 1 - .../AudioWorkflowRoutingSlipBuilder.cs | 1 - .../DatabaseDependencyInjection.cs | 1 - ...60705123932_AddTrackProcessingStateSaga.cs | 3 +- ...05125356_AddPlayListProcessingStateSaga.cs | 3 +- .../20260713234847_AddListeningHistory.cs | 3 +- ...60716214752_AddArtistsAndTrackOwnership.cs | 1 - ...17172507_SplitTrackIntoLocalAndExternal.cs | 1 - .../Migrations/20260720180747_AddAlbums.cs | 3 +- .../Migrations/20260721155102_AddMixes.cs | 3 +- .../20260721162102_DropMixGeneratedOn.cs | 3 +- .../20260724181012_AddExternalAlbums.cs | 3 +- .../Musify.Api/OpenApi/OpenApiExtensions.cs | 2 -- backend/Hosts/Musify.Worker/Program.cs | 2 -- .../CreateAlbumRequestValidatorTests.cs | 30 +++++++++++----- .../Albums/CreateAlbumCommandHandlerTests.cs | 4 +-- ...GenerateMixesForUserCommandHandlerTests.cs | 3 +- ...uTubeTrackToPlayListCommandHandlerTests.cs | 1 - .../CreatePlayListCommandHandlerTests.cs | 1 - .../Tracks/GetTrackCoverQueryHandlerTests.cs | 1 - .../AuditableEntityInterceptorTests.cs | 1 - .../Services/PictureServiceTests.cs | 6 ++-- .../Services/StorageServiceTests.cs | 36 +++++++------------ 24 files changed, 48 insertions(+), 66 deletions(-) diff --git a/backend/Core/Musify.Application/ApplicationDependencyInjection.cs b/backend/Core/Musify.Application/ApplicationDependencyInjection.cs index fd8c5d5..41e0185 100644 --- a/backend/Core/Musify.Application/ApplicationDependencyInjection.cs +++ b/backend/Core/Musify.Application/ApplicationDependencyInjection.cs @@ -1,4 +1,3 @@ -using Mediator; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Musify.Application.Configuration; diff --git a/backend/Core/Musify.Application/Tracks/Responses/TrackApplicationResponse.cs b/backend/Core/Musify.Application/Tracks/Responses/TrackApplicationResponse.cs index 3d57a7b..fb7e546 100644 --- a/backend/Core/Musify.Application/Tracks/Responses/TrackApplicationResponse.cs +++ b/backend/Core/Musify.Application/Tracks/Responses/TrackApplicationResponse.cs @@ -1,4 +1,3 @@ -using System.Linq; using Musify.Domain.Entities; using Musify.Domain.ValueObjects; diff --git a/backend/Core/Musify.Infrastructure/MassTransit/RoutingSlip/Builders/AudioWorkflowRoutingSlipBuilder.cs b/backend/Core/Musify.Infrastructure/MassTransit/RoutingSlip/Builders/AudioWorkflowRoutingSlipBuilder.cs index eee7bb1..2d807b1 100644 --- a/backend/Core/Musify.Infrastructure/MassTransit/RoutingSlip/Builders/AudioWorkflowRoutingSlipBuilder.cs +++ b/backend/Core/Musify.Infrastructure/MassTransit/RoutingSlip/Builders/AudioWorkflowRoutingSlipBuilder.cs @@ -4,7 +4,6 @@ using Musify.Application.Events; using Musify.Infrastructure.Configuration; using Musify.Infrastructure.MassTransit.Activities.Audio; using Musify.Infrastructure.MassTransit.Activities.Files; -using Musify.Infrastructure.MassTransit.Activities; using Musify.Infrastructure.MassTransit.Arguments; using Musify.Infrastructure.MassTransit.Consumers; diff --git a/backend/Core/Musify.Infrastructure/Persistence/DatabaseDependencyInjection.cs b/backend/Core/Musify.Infrastructure/Persistence/DatabaseDependencyInjection.cs index a7fa1a8..5052808 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/DatabaseDependencyInjection.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/DatabaseDependencyInjection.cs @@ -1,4 +1,3 @@ -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705123932_AddTrackProcessingStateSaga.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705123932_AddTrackProcessingStateSaga.cs index 2a0c159..1da5f70 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705123932_AddTrackProcessingStateSaga.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705123932_AddTrackProcessingStateSaga.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705125356_AddPlayListProcessingStateSaga.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705125356_AddPlayListProcessingStateSaga.cs index bb964d8..cbed3e0 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705125356_AddPlayListProcessingStateSaga.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260705125356_AddPlayListProcessingStateSaga.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260713234847_AddListeningHistory.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260713234847_AddListeningHistory.cs index 3e44c68..cf43852 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260713234847_AddListeningHistory.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260713234847_AddListeningHistory.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260716214752_AddArtistsAndTrackOwnership.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260716214752_AddArtistsAndTrackOwnership.cs index 47d18d9..2565e4e 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260716214752_AddArtistsAndTrackOwnership.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260716214752_AddArtistsAndTrackOwnership.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260717172507_SplitTrackIntoLocalAndExternal.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260717172507_SplitTrackIntoLocalAndExternal.cs index 5880c3a..277bb48 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260717172507_SplitTrackIntoLocalAndExternal.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260717172507_SplitTrackIntoLocalAndExternal.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260720180747_AddAlbums.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260720180747_AddAlbums.cs index 4947eb3..c9a4c1b 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260720180747_AddAlbums.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260720180747_AddAlbums.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721155102_AddMixes.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721155102_AddMixes.cs index f04305d..5b53094 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721155102_AddMixes.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721155102_AddMixes.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721162102_DropMixGeneratedOn.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721162102_DropMixGeneratedOn.cs index 7c8f66f..7b35949 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721162102_DropMixGeneratedOn.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260721162102_DropMixGeneratedOn.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260724181012_AddExternalAlbums.cs b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260724181012_AddExternalAlbums.cs index d35e870..05d396a 100644 --- a/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260724181012_AddExternalAlbums.cs +++ b/backend/Core/Musify.Infrastructure/Persistence/Migrations/20260724181012_AddExternalAlbums.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/backend/Hosts/Musify.Api/OpenApi/OpenApiExtensions.cs b/backend/Hosts/Musify.Api/OpenApi/OpenApiExtensions.cs index 6a7b6cc..6f00c38 100644 --- a/backend/Hosts/Musify.Api/OpenApi/OpenApiExtensions.cs +++ b/backend/Hosts/Musify.Api/OpenApi/OpenApiExtensions.cs @@ -1,5 +1,3 @@ -using Microsoft.AspNetCore.OpenApi; - namespace Musify.Api.OpenApi; public static class OpenApiExtensions diff --git a/backend/Hosts/Musify.Worker/Program.cs b/backend/Hosts/Musify.Worker/Program.cs index fbfd431..af4d9a1 100644 --- a/backend/Hosts/Musify.Worker/Program.cs +++ b/backend/Hosts/Musify.Worker/Program.cs @@ -1,6 +1,4 @@ using Hangfire; -using Mediator; -using Microsoft.Extensions.DependencyInjection; using Musify.Application.Configuration; using Musify.Application.Services; using Musify.Infrastructure.Jobs; diff --git a/backend/Tests/Musify.Api.Tests/Validators/CreateAlbumRequestValidatorTests.cs b/backend/Tests/Musify.Api.Tests/Validators/CreateAlbumRequestValidatorTests.cs index 739991b..6cd9099 100644 --- a/backend/Tests/Musify.Api.Tests/Validators/CreateAlbumRequestValidatorTests.cs +++ b/backend/Tests/Musify.Api.Tests/Validators/CreateAlbumRequestValidatorTests.cs @@ -41,20 +41,34 @@ public sealed class CreateAlbumRequestValidatorTests Assert.False(result.IsValid); } - [Theory] - [InlineData(1876)] - [InlineData(1877)] - public void Validate_ReleaseYearAtOrBeforeTheEarliestBoundary(int year) + [Fact] + public void Validate_ReleaseYearBeforeTheEarliestBoundary_Fails() { - var result = validator.Validate(new CreateAlbumRequest("Title", null, year)); + var result = validator.Validate(new CreateAlbumRequest("Title", null, AlbumReleaseYear.Earliest - 1)); - Assert.Equal(year >= 1877, result.IsValid); + Assert.False(result.IsValid); } [Fact] - public void Validate_ReleaseYearMoreThanOneYearInTheFuture_Fails() + public void Validate_ReleaseYearAtTheEarliestBoundary_Passes() { - var result = validator.Validate(new CreateAlbumRequest("Title", null, DateTime.UtcNow.Year + 2)); + var result = validator.Validate(new CreateAlbumRequest("Title", null, AlbumReleaseYear.Earliest)); + + Assert.True(result.IsValid); + } + + [Fact] + public void Validate_ReleaseYearAtTheLatestBoundary_Passes() + { + var result = validator.Validate(new CreateAlbumRequest("Title", null, AlbumReleaseYear.Latest)); + + Assert.True(result.IsValid); + } + + [Fact] + public void Validate_ReleaseYearPastTheLatestBoundary_Fails() + { + var result = validator.Validate(new CreateAlbumRequest("Title", null, AlbumReleaseYear.Latest + 1)); Assert.False(result.IsValid); } diff --git a/backend/Tests/Musify.Application.Tests/Albums/CreateAlbumCommandHandlerTests.cs b/backend/Tests/Musify.Application.Tests/Albums/CreateAlbumCommandHandlerTests.cs index 0f78f82..58c0da6 100644 --- a/backend/Tests/Musify.Application.Tests/Albums/CreateAlbumCommandHandlerTests.cs +++ b/backend/Tests/Musify.Application.Tests/Albums/CreateAlbumCommandHandlerTests.cs @@ -1,3 +1,4 @@ +using ErrorOr; using Musify.Application.Albums; using Musify.Application.Tests.TestSupport; using Xunit; @@ -37,7 +38,6 @@ public sealed class CreateAlbumCommandHandlerTests : HandlerTestBase var result = await CreateHandler().Handle(command, CancellationToken.None); - Assert.True(result.IsError); - Assert.Equal(ErrorOr.ErrorType.NotFound, result.FirstError.Type); + Assert.Equal(ErrorType.NotFound, result.FirstError.Type); } } diff --git a/backend/Tests/Musify.Application.Tests/Mixes/GenerateMixesForUserCommandHandlerTests.cs b/backend/Tests/Musify.Application.Tests/Mixes/GenerateMixesForUserCommandHandlerTests.cs index 8318ad8..6cce92e 100644 --- a/backend/Tests/Musify.Application.Tests/Mixes/GenerateMixesForUserCommandHandlerTests.cs +++ b/backend/Tests/Musify.Application.Tests/Mixes/GenerateMixesForUserCommandHandlerTests.cs @@ -3,7 +3,6 @@ using Musify.Application.Contracts; using Musify.Application.Mixes; using Musify.Application.Tests.TestSupport; using Musify.Domain.Entities; -using Musify.Domain.ValueObjects; using NSubstitute; using Xunit; @@ -47,7 +46,7 @@ public sealed class GenerateMixesForUserCommandHandlerTests : HandlerTestBase youTubeMusicService .SearchSongsAsync(Arg.Any(), Arg.Any(), Arg.Any()) .Returns(new YouTubeSearchResult( - [new YouTubeSongResult("yt-1", "YouTube Song", "Seed Artist", "Album", 200, "https://img/thumb.jpg", false, [])], + [new YouTubeSongResult("yt-1", "YouTube Song", "Seed Artist", "Album", 200, "https://img/thumb.jpg", IsExplicit: false, [] )], ContinuationToken: string.Empty)); youTubeMusicService.ResolveArtworkUrl(Arg.Any()).Returns(callInfo => callInfo.Arg()); diff --git a/backend/Tests/Musify.Application.Tests/PlayLists/AddYouTubeTrackToPlayListCommandHandlerTests.cs b/backend/Tests/Musify.Application.Tests/PlayLists/AddYouTubeTrackToPlayListCommandHandlerTests.cs index 68c570c..8810762 100644 --- a/backend/Tests/Musify.Application.Tests/PlayLists/AddYouTubeTrackToPlayListCommandHandlerTests.cs +++ b/backend/Tests/Musify.Application.Tests/PlayLists/AddYouTubeTrackToPlayListCommandHandlerTests.cs @@ -5,7 +5,6 @@ using Musify.Application.PlayLists; using Musify.Application.Services; using Musify.Application.Tests.TestSupport; using Musify.Domain.Entities; -using Musify.Domain.ValueObjects; using NSubstitute; using Xunit; diff --git a/backend/Tests/Musify.Application.Tests/PlayLists/CreatePlayListCommandHandlerTests.cs b/backend/Tests/Musify.Application.Tests/PlayLists/CreatePlayListCommandHandlerTests.cs index 99a55b9..b09d93e 100644 --- a/backend/Tests/Musify.Application.Tests/PlayLists/CreatePlayListCommandHandlerTests.cs +++ b/backend/Tests/Musify.Application.Tests/PlayLists/CreatePlayListCommandHandlerTests.cs @@ -1,5 +1,4 @@ using ErrorOr; -using Musify.Application.Configuration; using Musify.Application.Contracts; using Musify.Application.PlayLists; using Musify.Application.Services; diff --git a/backend/Tests/Musify.Application.Tests/Tracks/GetTrackCoverQueryHandlerTests.cs b/backend/Tests/Musify.Application.Tests/Tracks/GetTrackCoverQueryHandlerTests.cs index cac06ac..0ee579e 100644 --- a/backend/Tests/Musify.Application.Tests/Tracks/GetTrackCoverQueryHandlerTests.cs +++ b/backend/Tests/Musify.Application.Tests/Tracks/GetTrackCoverQueryHandlerTests.cs @@ -1,7 +1,6 @@ using ErrorOr; using Musify.Application.Tests.TestSupport; using Musify.Application.Tracks; -using Musify.Domain.ValueObjects; using Xunit; namespace Musify.Application.Tests.Tracks; diff --git a/backend/Tests/Musify.Infrastructure.Tests/Persistence/AuditableEntityInterceptorTests.cs b/backend/Tests/Musify.Infrastructure.Tests/Persistence/AuditableEntityInterceptorTests.cs index 6f47980..336fe42 100644 --- a/backend/Tests/Musify.Infrastructure.Tests/Persistence/AuditableEntityInterceptorTests.cs +++ b/backend/Tests/Musify.Infrastructure.Tests/Persistence/AuditableEntityInterceptorTests.cs @@ -1,4 +1,3 @@ -using Microsoft.EntityFrameworkCore; using Musify.Domain.Entities; using Musify.Infrastructure.Tests.TestSupport; using Xunit; diff --git a/backend/Tests/Musify.Infrastructure.Tests/Services/PictureServiceTests.cs b/backend/Tests/Musify.Infrastructure.Tests/Services/PictureServiceTests.cs index 11ea899..e7178cd 100644 --- a/backend/Tests/Musify.Infrastructure.Tests/Services/PictureServiceTests.cs +++ b/backend/Tests/Musify.Infrastructure.Tests/Services/PictureServiceTests.cs @@ -27,9 +27,9 @@ public sealed class PictureServiceTests await using var resized = await CreateService().ResizePictureAsWebpAsync(source, 200, 200, CancellationToken.None); using var result = await Image.LoadAsync(resized); - Assert.True(result.Width <= 200); - Assert.True(result.Height <= 200); - Assert.True(result.Width == 200 || result.Height == 200); + Assert.InRange(result.Width, 1, 200); + Assert.InRange(result.Height, 1, 200); + Assert.True(result.Width == 200 || result.Height == 200, "expected the longer side to land exactly on the target box"); } [Fact] diff --git a/backend/Tests/Musify.Infrastructure.Tests/Services/StorageServiceTests.cs b/backend/Tests/Musify.Infrastructure.Tests/Services/StorageServiceTests.cs index d597271..fbc6faa 100644 --- a/backend/Tests/Musify.Infrastructure.Tests/Services/StorageServiceTests.cs +++ b/backend/Tests/Musify.Infrastructure.Tests/Services/StorageServiceTests.cs @@ -1,7 +1,9 @@ using System.Net; +using System.Net.Http.Headers; using System.Text; using Microsoft.Extensions.Logging.Abstractions; using Musify.Infrastructure.Configuration; +using Musify.Infrastructure.Persistence; using Musify.Infrastructure.Services; using Musify.Infrastructure.Tests.TestSupport; using Xunit; @@ -9,9 +11,12 @@ using Xunit; namespace Musify.Infrastructure.Tests.Services; [Collection(InfrastructureCollection.Name)] -public sealed class StorageServiceTests(InfrastructureTestFixture fixture) +public sealed class StorageServiceTests(InfrastructureTestFixture fixture) : IAsyncLifetime { - private StorageService CreateService(out Musify.Infrastructure.Persistence.Database database) + private Database database = null!; + private StorageService service = null!; + + public Task InitializeAsync() { database = fixture.CreateDatabase(); var storageConfiguration = new InfrastructureStorageConfiguration @@ -22,14 +27,15 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) ForcePathStyle = true, UseHttp = true, }; - return new StorageService(database, fixture.CreateS3Client(), NullLogger.Instance, storageConfiguration); + service = new StorageService(database, fixture.CreateS3Client(), NullLogger.Instance, storageConfiguration); + return Task.CompletedTask; } + public Task DisposeAsync() => database.DisposeAsync().AsTask(); + [Fact] public async Task UploadThenGetFile_RoundTripsTheSameBytes() { - var service = CreateService(out var database); - await using var _ = database; var key = $"tests/{Guid.NewGuid():N}/round-trip.txt"; var content = "hello seaweedfs"u8.ToArray(); @@ -45,8 +51,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task HeadObjectAsync_ExistingObject_ReturnsMetadata() { - var service = CreateService(out var database); - await using var _ = database; var key = $"tests/{Guid.NewGuid():N}/head.txt"; await service.UploadFileAsync(new MemoryStream("x"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, key, CancellationToken.None); @@ -59,9 +63,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task HeadObjectAsync_MissingObject_ReturnsNull() { - var service = CreateService(out var database); - await using var _ = database; - var metadata = await service.HeadObjectAsync(InfrastructureTestFixture.S3Bucket, $"tests/{Guid.NewGuid():N}/missing.txt", CancellationToken.None); Assert.Null(metadata); @@ -70,8 +71,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task RemoveFileAsync_ExistingObject_DeletesIt() { - var service = CreateService(out var database); - await using var _ = database; var key = $"tests/{Guid.NewGuid():N}/to-remove.txt"; await service.UploadFileAsync(new MemoryStream("x"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, key, CancellationToken.None); @@ -83,8 +82,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task CopyFileAsync_CopiesToTheDestinationKey() { - var service = CreateService(out var database); - await using var _ = database; var sourceKey = $"tests/{Guid.NewGuid():N}/source.txt"; var destinationKey = $"tests/{Guid.NewGuid():N}/destination.txt"; await service.UploadFileAsync(new MemoryStream("copy-me"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, sourceKey, CancellationToken.None); @@ -97,8 +94,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task ListObjectsAsync_ReturnsEveryObjectUnderThePrefix() { - var service = CreateService(out var database); - await using var _ = database; var prefix = $"tests/{Guid.NewGuid():N}"; await service.UploadFileAsync(new MemoryStream("a"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, $"{prefix}/a.txt", CancellationToken.None); await service.UploadFileAsync(new MemoryStream("b"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, $"{prefix}/b.txt", CancellationToken.None); @@ -113,8 +108,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task RemoveFolderAsync_DeletesEveryObjectUnderThePrefix() { - var service = CreateService(out var database); - await using var _ = database; var prefix = $"tests/{Guid.NewGuid():N}"; await service.UploadFileAsync(new MemoryStream("a"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, $"{prefix}/a.txt", CancellationToken.None); await service.UploadFileAsync(new MemoryStream("b"u8.ToArray()), "text/plain", InfrastructureTestFixture.S3Bucket, $"{prefix}/nested/b.txt", CancellationToken.None); @@ -130,8 +123,6 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) [Fact] public async Task GetUploadUrlAsync_PresignedPut_CanActuallyUploadTheObject() { - var service = CreateService(out var database); - await using var _ = database; var key = $"tests/{Guid.NewGuid():N}/presigned.txt"; var uploadUrl = await service.GetUploadUrlAsync( @@ -145,15 +136,14 @@ public sealed class StorageServiceTests(InfrastructureTestFixture fixture) // signs Content-Type byte-for-byte) and the server answers 403 SignatureDoesNotMatch. Content = new ByteArrayContent(Encoding.UTF8.GetBytes("presigned content")) }; - request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/plain"); + request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); // GetUploadUrlAsync defaults preventOverwrite to true, which signs the URL together with // this header (see StorageService.GetUploadUrlAsync) — the actual PUT has to send it too, // or the signature no longer matches and the server answers 403. request.Headers.TryAddWithoutValidation("If-None-Match", "*"); var response = await httpClient.SendAsync(request); - var responseBody = await response.Content.ReadAsStringAsync(); - Assert.True(response.StatusCode == HttpStatusCode.OK, $"status={response.StatusCode}, body={responseBody}"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); var metadata = await service.HeadObjectAsync(InfrastructureTestFixture.S3Bucket, key, CancellationToken.None); Assert.NotNull(metadata); Assert.Equal("presigned content".Length, metadata.ContentLength);