Small changes
This commit is contained in:
@@ -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<UserApplicationResponse>();
|
||||
user!.Id.Should().Be(id);
|
||||
UserApplicationResponse user = await get.Content.ReadFromJsonAsync<UserApplicationResponse>()
|
||||
?? 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<ValidationProblemResponse>();
|
||||
problem!.Errors.Should().ContainKey(nameof(CreateUserRequest.Name));
|
||||
ValidationProblemResponse problem = await response.Content.ReadFromJsonAsync<ValidationProblemResponse>()
|
||||
?? 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<PlayListApplicationResponse>();
|
||||
playList!.Name.Should().Be("My Mix");
|
||||
PlayListApplicationResponse playList = await response.Content.ReadFromJsonAsync<PlayListApplicationResponse>()
|
||||
?? 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<TrackUploadUrlsLikeResponse>();
|
||||
body!.PictureUploadUrl.Should().Be("https://signed.example/put");
|
||||
TrackUploadUrlsLikeResponse body = await response.Content.ReadFromJsonAsync<TrackUploadUrlsLikeResponse>()
|
||||
?? throw new InvalidOperationException("The response body was null.");
|
||||
body.PictureUploadUrl.Should().Be("https://signed.example/put");
|
||||
body.AudioUploadUrl.Should().Be("https://signed.example/put");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +47,10 @@ public sealed class MusifyApiFactory : WebApplicationFactory<Program>
|
||||
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
// Never start the RabbitMQ bus, EF outbox delivery or OTLP exporter in tests.
|
||||
services.RemoveAll<IHostedService>();
|
||||
|
||||
_connection.Open();
|
||||
|
||||
// Replace the Npgsql-backed IDatabase with a shared SQLite TestDatabase.
|
||||
services.RemoveAll<IDatabase>();
|
||||
services.AddScoped<IDatabase>(_ =>
|
||||
{
|
||||
@@ -64,7 +62,6 @@ public sealed class MusifyApiFactory : WebApplicationFactory<Program>
|
||||
return db;
|
||||
});
|
||||
|
||||
// Replace S3 and MassTransit with controllable test doubles.
|
||||
services.RemoveAll<IStorageService>();
|
||||
services.AddScoped(_ => Storage);
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
<RootNamespace>Musify.WebApi.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- ResultHttpExtensions returns Microsoft.AspNetCore.Http.IResult, so the test project
|
||||
needs the ASP.NET Core shared framework to inspect the produced result types. -->
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
@@ -30,7 +28,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\WebApi\WebApi.csproj" />
|
||||
<!-- Reuse TestDatabase / TestData helpers from the Application test project. -->
|
||||
<ProjectReference Include="..\..\..\MusifyBackend\Tests\Musify.Application.Tests\Musify.Application.Tests.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -24,5 +24,4 @@ app
|
||||
|
||||
app.Run();
|
||||
|
||||
// Exposed so WebApplicationFactory<Program> can bootstrap the app in integration tests.
|
||||
public partial class Program { }
|
||||
|
||||
Reference in New Issue
Block a user