Files
Musify/backend/Tests/Musify.Application.Tests/Albums/CreateAlbumCommandHandlerTests.cs
T
Admin b57949a6bc 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.
2026-09-09 21:53:00 +02:00

44 lines
1.5 KiB
C#

using ErrorOr;
using Musify.Application.Albums;
using Musify.Application.Tests.TestSupport;
using Xunit;
namespace Musify.Application.Tests.Albums;
public sealed class CreateAlbumCommandHandlerTests : HandlerTestBase
{
private CreateAlbumCommandHandler CreateHandler() => new(Database, NoOpLogger<CreateAlbumCommandHandler>());
[Fact]
public async Task Handle_UserExists_CreatesAlbumAndReturnsIt()
{
var owner = TestEntities.User();
await SeedAsync(owner);
var command = new CreateAlbumCommand(owner.Id, " My Album ", "A description", 2024);
var result = await CreateHandler().Handle(command, CancellationToken.None);
Assert.False(result.IsError);
Assert.Equal("My Album", result.Value.Title);
Assert.Equal("A description", result.Value.Description);
Assert.Equal(2024, result.Value.ReleaseYear);
Assert.Equal(owner.Id, result.Value.OwnerUserId);
Assert.Equal(0, result.Value.TrackCount);
var stored = await Database.UserAlbums.FindAsync(result.Value.Id);
Assert.NotNull(stored);
Assert.Equal("MY ALBUM", stored.NormalizedTitle);
}
[Fact]
public async Task Handle_UserDoesNotExist_ReturnsNotFound()
{
var command = new CreateAlbumCommand(UserId: 404, "Orphan Album", Description: null, ReleaseYear: null);
var result = await CreateHandler().Handle(command, CancellationToken.None);
Assert.Equal(ErrorType.NotFound, result.FirstError.Type);
}
}