Migrate backend test suite from xUnit v2 to v3

- Directory.Packages.props: xunit 2.9.3 -> xunit.v3 4.0.0, bump
  xunit.runner.visualstudio to the matching 4.0.0
- All 5 test csproj: xunit -> xunit.v3 package reference, add
  <OutputType>Exe</OutputType> (v3 test projects are standalone
  executables)
- backend/global.json: opt dotnet test into the new MTP-native mode
  (.NET 10 SDK removed the old VSTest bridge for MTP-based test
  projects like xunit v3)
- IAsyncLifetime implementations (HandlerTestBase, ApiTestFixture,
  InfrastructureTestFixture, StorageServiceTests): v3's IAsyncLifetime
  now IS IAsyncDisposable, so InitializeAsync/DisposeAsync return
  ValueTask instead of Task. ApiTestFixture specifically now overrides
  WebApplicationFactory.DisposeAsync instead of implementing
  IAsyncLifetime.DisposeAsync explicitly, since v3 collapses both to
  the same single DisposeAsync slot
- Replaced CancellationToken.None with TestContext.Current.CancellationToken
  across the suite (a v3-only API) and added it to every call that
  was silently omitting a CancellationToken argument, per the new
  xUnit1051 analyzer warnings that came with the v3 package

Verified: dotnet build (0 warnings, 0 errors) and dotnet test, 250/250
passing under the new MTP runner.
This commit is contained in:
2026-09-09 22:11:29 +02:00
parent b57949a6bc
commit 98e6dfc4c4
62 changed files with 286 additions and 272 deletions
@@ -15,7 +15,7 @@ public sealed class DatabaseTests(InfrastructureTestFixture fixture)
await using var database = fixture.CreateDatabase();
var user = new User { Id = Random.Shared.NextInt64(1, long.MaxValue), Name = "roundtrip-user", NormalizedName = "ROUNDTRIP-USER" };
await database.Users.AddAsync(user);
await database.Users.AddAsync(user, TestContext.Current.CancellationToken);
var track = new LocalTrack
{
@@ -27,11 +27,11 @@ public sealed class DatabaseTests(InfrastructureTestFixture fixture)
Pictures = new TrackPictures { OriginalName = "cover.webp", ProcessingStatus = ProcessingStatus.Pending },
Audio = new TrackAudio { OriginalName = "song.mp3", TranscodeStatus = ProcessingStatus.Pending }
};
await database.LocalTracks.AddAsync(track);
await database.SaveChangesAsync(CancellationToken.None);
await database.LocalTracks.AddAsync(track, TestContext.Current.CancellationToken);
await database.SaveChangesAsync(TestContext.Current.CancellationToken);
await using var reloaded = fixture.CreateDatabase();
var stored = await reloaded.Tracks.AsNoTracking().SingleAsync(t => t.Id == track.Id);
var stored = await reloaded.Tracks.AsNoTracking().SingleAsync(t => t.Id == track.Id, TestContext.Current.CancellationToken);
Assert.IsType<LocalTrack>(stored);
Assert.Equal("Round Trip Track", stored.Title);
@@ -46,13 +46,13 @@ public sealed class DatabaseTests(InfrastructureTestFixture fixture)
await using var database = fixture.CreateDatabase();
var videoId = $"dup-{Guid.NewGuid():N}";
await database.ExternalTracks.AddAsync(BuildExternalTrack(videoId));
await database.SaveChangesAsync(CancellationToken.None);
await database.ExternalTracks.AddAsync(BuildExternalTrack(videoId), TestContext.Current.CancellationToken);
await database.SaveChangesAsync(TestContext.Current.CancellationToken);
await using var second = fixture.CreateDatabase();
await second.ExternalTracks.AddAsync(BuildExternalTrack(videoId));
await second.ExternalTracks.AddAsync(BuildExternalTrack(videoId), TestContext.Current.CancellationToken);
await Assert.ThrowsAsync<DbUpdateException>(() => second.SaveChangesAsync(CancellationToken.None));
await Assert.ThrowsAsync<DbUpdateException>(() => second.SaveChangesAsync(TestContext.Current.CancellationToken));
}
[Fact]
@@ -66,16 +66,16 @@ public sealed class DatabaseTests(InfrastructureTestFixture fixture)
var link = new AlbumHasTrack { AlbumId = album.Id, TrackId = track.Id, TrackNumber = 1 };
await database.AddRangeAsync(user, album, track, link);
await database.SaveChangesAsync(CancellationToken.None);
await database.SaveChangesAsync(TestContext.Current.CancellationToken);
await using var deleter = fixture.CreateDatabase();
var albumToDelete = await deleter.UserAlbums.SingleAsync(a => a.Id == album.Id);
var albumToDelete = await deleter.UserAlbums.SingleAsync(a => a.Id == album.Id, TestContext.Current.CancellationToken);
deleter.UserAlbums.Remove(albumToDelete);
await deleter.SaveChangesAsync(CancellationToken.None);
await deleter.SaveChangesAsync(TestContext.Current.CancellationToken);
await using var verifier = fixture.CreateDatabase();
Assert.False(await verifier.AlbumHasTracks.AnyAsync(l => l.AlbumId == album.Id));
Assert.True(await verifier.ExternalTracks.AnyAsync(t => t.Id == track.Id));
Assert.False(await verifier.AlbumHasTracks.AnyAsync(l => l.AlbumId == album.Id, TestContext.Current.CancellationToken));
Assert.True(await verifier.ExternalTracks.AnyAsync(t => t.Id == track.Id, TestContext.Current.CancellationToken));
}
private static ExternalTrack BuildExternalTrack(string externalId) => new()