From fd41053030e4d24f3b79fd8639a11a214a6ec51a Mon Sep 17 00:00:00 2001 From: XShine555 Date: Fri, 29 May 2026 13:49:49 +0200 Subject: [PATCH] Small changes --- .../Integration/ApiIntegrationTests.cs | 20 +++++++++++-------- .../Integration/MusifyApiFactory.cs | 3 --- .../Musify.WebApi.Tests.csproj | 3 --- .../Validators/ValidatorTests.cs | 1 - WebApi/Program.cs | 1 - 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Tests/Musify.WebApi.Tests/Integration/ApiIntegrationTests.cs b/Tests/Musify.WebApi.Tests/Integration/ApiIntegrationTests.cs index bfac0f0..af7aae9 100644 --- a/Tests/Musify.WebApi.Tests/Integration/ApiIntegrationTests.cs +++ b/Tests/Musify.WebApi.Tests/Integration/ApiIntegrationTests.cs @@ -38,8 +38,9 @@ public sealed class ApiIntegrationTests(MusifyApiFactory factory) var get = await _client.GetAsync($"/users/{id}"); get.StatusCode.Should().Be(HttpStatusCode.OK); - var user = await get.Content.ReadFromJsonAsync(); - user!.Id.Should().Be(id); + UserApplicationResponse user = await get.Content.ReadFromJsonAsync() + ?? throw new InvalidOperationException("The response body was null."); + user.Id.Should().Be(id); user.Name.Should().Be("Alice"); } @@ -49,8 +50,9 @@ public sealed class ApiIntegrationTests(MusifyApiFactory factory) var response = await _client.PostAsJsonAsync("/users/", new CreateUserRequest(Guid.Empty, "", null, null)); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - var problem = await response.Content.ReadFromJsonAsync(); - problem!.Errors.Should().ContainKey(nameof(CreateUserRequest.Name)); + ValidationProblemResponse problem = await response.Content.ReadFromJsonAsync() + ?? throw new InvalidOperationException("The response body was null."); + problem.Errors.Should().ContainKey(nameof(CreateUserRequest.Name)); } [Fact] @@ -80,8 +82,9 @@ public sealed class ApiIntegrationTests(MusifyApiFactory factory) new CreatePlayListRequest("My Mix", "A description", null)); response.StatusCode.Should().Be(HttpStatusCode.Created); - var playList = await response.Content.ReadFromJsonAsync(); - playList!.Name.Should().Be("My Mix"); + PlayListApplicationResponse playList = await response.Content.ReadFromJsonAsync() + ?? throw new InvalidOperationException("The response body was null."); + playList.Name.Should().Be("My Mix"); var get = await _client.GetAsync($"/playLists/{playList.Id}"); get.StatusCode.Should().Be(HttpStatusCode.OK); @@ -129,8 +132,9 @@ public sealed class ApiIntegrationTests(MusifyApiFactory factory) new RequestTrackUploadUrlsRequest("png", "image/png", "mp3", "audio/mpeg")); response.StatusCode.Should().Be(HttpStatusCode.OK); - var body = await response.Content.ReadFromJsonAsync(); - body!.PictureUploadUrl.Should().Be("https://signed.example/put"); + TrackUploadUrlsLikeResponse body = await response.Content.ReadFromJsonAsync() + ?? throw new InvalidOperationException("The response body was null."); + body.PictureUploadUrl.Should().Be("https://signed.example/put"); body.AudioUploadUrl.Should().Be("https://signed.example/put"); } } diff --git a/Tests/Musify.WebApi.Tests/Integration/MusifyApiFactory.cs b/Tests/Musify.WebApi.Tests/Integration/MusifyApiFactory.cs index 6085f16..71cb896 100644 --- a/Tests/Musify.WebApi.Tests/Integration/MusifyApiFactory.cs +++ b/Tests/Musify.WebApi.Tests/Integration/MusifyApiFactory.cs @@ -47,12 +47,10 @@ public sealed class MusifyApiFactory : WebApplicationFactory builder.ConfigureTestServices(services => { - // Never start the RabbitMQ bus, EF outbox delivery or OTLP exporter in tests. services.RemoveAll(); _connection.Open(); - // Replace the Npgsql-backed IDatabase with a shared SQLite TestDatabase. services.RemoveAll(); services.AddScoped(_ => { @@ -64,7 +62,6 @@ public sealed class MusifyApiFactory : WebApplicationFactory return db; }); - // Replace S3 and MassTransit with controllable test doubles. services.RemoveAll(); services.AddScoped(_ => Storage); diff --git a/Tests/Musify.WebApi.Tests/Musify.WebApi.Tests.csproj b/Tests/Musify.WebApi.Tests/Musify.WebApi.Tests.csproj index 8b5774e..356c23c 100644 --- a/Tests/Musify.WebApi.Tests/Musify.WebApi.Tests.csproj +++ b/Tests/Musify.WebApi.Tests/Musify.WebApi.Tests.csproj @@ -8,8 +8,6 @@ Musify.WebApi.Tests - @@ -30,7 +28,6 @@ - diff --git a/Tests/Musify.WebApi.Tests/Validators/ValidatorTests.cs b/Tests/Musify.WebApi.Tests/Validators/ValidatorTests.cs index dfca788..046f9ed 100644 --- a/Tests/Musify.WebApi.Tests/Validators/ValidatorTests.cs +++ b/Tests/Musify.WebApi.Tests/Validators/ValidatorTests.cs @@ -142,7 +142,6 @@ public sealed class UpdatePlayListRequestValidatorTests [Fact] public void Empty_string_name_is_allowed_by_length_rule() { - // Only a MaximumLength rule applies, so an empty (non-null) string passes. var model = new UpdatePlayListRequest("", null, null); _validator.TestValidate(model).ShouldNotHaveValidationErrorFor(x => x.NewName); } diff --git a/WebApi/Program.cs b/WebApi/Program.cs index 03be246..96097c7 100644 --- a/WebApi/Program.cs +++ b/WebApi/Program.cs @@ -24,5 +24,4 @@ app app.Run(); -// Exposed so WebApplicationFactory can bootstrap the app in integration tests. public partial class Program { }