Adds music stack test coverage and fixes playlist cache and stream error handling

This commit is contained in:
BinaryAlley committed 2026-10-29 15:46:24 +02:00
1 parent 394f6b510c
commit aba803b106
197 files changed
+29081 -34

No files matched your search

@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
/// <summary>
/// Fixture class for the <see cref="MediaItemId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaItemIdFixture
{
/// <summary>
/// Creates a random valid <see cref="MediaItemId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the media item Id.</param>
/// <returns>The created <see cref="MediaItemId"/>.</returns>
public MediaItemId Create(
Guid? value = null)
{
return MediaItemId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="MediaItemId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaItemId"/> instances.</returns>
public List<MediaItemId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
/// <summary>
/// Fixture class for the <see cref="UserId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserIdFixture
{
/// <summary>
/// Creates a random valid <see cref="UserId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the user Id.</param>
/// <returns>The created <see cref="UserId"/>.</returns>
public UserId Create(
Guid? value = null)
{
return UserId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="UserId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UserId"/> instances.</returns>
public List<UserId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
/// <summary>
/// Fixture class for the <see cref="PlaylistEntry"/> entity.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistEntryFixture
{
private const long MAXIMUM_RANDOM_POSITION = 1_000_000_000L;
private readonly Faker _faker = new();
private readonly PlaylistEntryIdFixture _playlistEntryIdFixture = new();
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="PlaylistEntry"/>.
/// </summary>
/// <param name="id">Optional. The Id of the entry.</param>
/// <param name="mediaItemId">Optional. The Id of the media item referenced by the entry.</param>
/// <param name="mediaItemType">Optional. The kind of media item referenced by the entry. Defaults to a music track, which is the kind a music playlist accepts.</param>
/// <param name="position">Optional. The sparse order key of the entry. Defaults to a bounded random key.</param>
/// <returns>The created <see cref="PlaylistEntry"/>.</returns>
public PlaylistEntry Create(
PlaylistEntryId? id = null,
MediaItemId? mediaItemId = null,
PlaylistMediaItemType? mediaItemType = null,
long? position = null)
{
return PlaylistEntry.Create(
id ?? _playlistEntryIdFixture.Create(),
mediaItemId ?? _mediaItemIdFixture.Create(),
mediaItemType ?? PlaylistMediaItemType.MusicTrack,
position ?? _faker.Random.Long(0, MAXIMUM_RANDOM_POSITION)).Value;
}
/// <summary>
/// Creates multiple <see cref="PlaylistEntry"/> instances with randomized test data and distinct positions.
/// </summary>
/// <remarks>
/// The positions are spaced apart and unique, so the created entries can be placed in the same playlist without violating the
/// uniqueness invariant of the sparse order keys.
/// </remarks>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistEntry"/> instances.</returns>
public List<PlaylistEntry> CreateMany(int count = 3)
{
long firstPosition = _faker.Random.Long(0, MAXIMUM_RANDOM_POSITION);
return [.. Enumerable.Range(0, count).Select(index => Create(position: firstPosition + index))];
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
/// <summary>
/// Fixture class for the <see cref="PlaylistCreatedDomainEvent"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistCreatedDomainEventFixture
{
private readonly Faker _faker = new();
private readonly PlaylistIdFixture _playlistIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="PlaylistCreatedDomainEvent"/>.
/// </summary>
/// <param name="id">Optional. The Id of the domain event.</param>
/// <param name="playlistId">Optional. The unique identifier of the playlist.</param>
/// <param name="userId">Optional. The unique identifier of the user that owns the playlist.</param>
/// <param name="name">Optional. The name of the playlist.</param>
/// <param name="type">Optional. The kind of media the playlist holds. Defaults to the only supported kind.</param>
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
/// <returns>The created <see cref="PlaylistCreatedDomainEvent"/>.</returns>
public PlaylistCreatedDomainEvent Create(
Guid? id = null,
PlaylistId? playlistId = null,
UserId? userId = null,
string? name = null,
PlaylistType? type = null,
DateTime? occurredOnUtc = null)
{
return new PlaylistCreatedDomainEvent(
id ?? Guid.NewGuid(),
playlistId ?? _playlistIdFixture.Create(),
userId ?? _userIdFixture.Create(),
name ?? _faker.Lorem.Sentence(3),
type ?? PlaylistType.Music,
occurredOnUtc ?? DateTime.UtcNow);
}
/// <summary>
/// Creates multiple <see cref="PlaylistCreatedDomainEvent"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistCreatedDomainEvent"/> instances.</returns>
public List<PlaylistCreatedDomainEvent> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
/// <summary>
/// Fixture class for the <see cref="PlaylistDeletedDomainEvent"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistDeletedDomainEventFixture
{
private readonly PlaylistIdFixture _playlistIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="PlaylistDeletedDomainEvent"/>.
/// </summary>
/// <param name="id">Optional. The Id of the domain event.</param>
/// <param name="playlistId">Optional. The unique identifier of the playlist.</param>
/// <param name="userId">Optional. The unique identifier of the user that owned the playlist.</param>
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
/// <returns>The created <see cref="PlaylistDeletedDomainEvent"/>.</returns>
public PlaylistDeletedDomainEvent Create(
Guid? id = null,
PlaylistId? playlistId = null,
UserId? userId = null,
DateTime? occurredOnUtc = null)
{
return new PlaylistDeletedDomainEvent(
id ?? Guid.NewGuid(),
playlistId ?? _playlistIdFixture.Create(),
userId ?? _userIdFixture.Create(),
occurredOnUtc ?? DateTime.UtcNow);
}
/// <summary>
/// Creates multiple <see cref="PlaylistDeletedDomainEvent"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistDeletedDomainEvent"/> instances.</returns>
public List<PlaylistDeletedDomainEvent> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Events;
/// <summary>
/// Fixture class for the <see cref="PlaylistDetailsUpdatedDomainEvent"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistDetailsUpdatedDomainEventFixture
{
private readonly Faker _faker = new();
private readonly PlaylistIdFixture _playlistIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="PlaylistDetailsUpdatedDomainEvent"/>.
/// </summary>
/// <param name="id">Optional. The Id of the domain event.</param>
/// <param name="playlistId">Optional. The unique identifier of the playlist.</param>
/// <param name="userId">Optional. The unique identifier of the user that owns the playlist.</param>
/// <param name="name">Optional. The new name of the playlist.</param>
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
/// <returns>The created <see cref="PlaylistDetailsUpdatedDomainEvent"/>.</returns>
public PlaylistDetailsUpdatedDomainEvent Create(
Guid? id = null,
PlaylistId? playlistId = null,
UserId? userId = null,
string? name = null,
DateTime? occurredOnUtc = null)
{
return new PlaylistDetailsUpdatedDomainEvent(
id ?? Guid.NewGuid(),
playlistId ?? _playlistIdFixture.Create(),
userId ?? _userIdFixture.Create(),
name ?? _faker.Lorem.Sentence(3),
occurredOnUtc ?? DateTime.UtcNow);
}
/// <summary>
/// Creates multiple <see cref="PlaylistDetailsUpdatedDomainEvent"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistDetailsUpdatedDomainEvent"/> instances.</returns>
public List<PlaylistDetailsUpdatedDomainEvent> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,79 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate;
/// <summary>
/// Fixture class for the <see cref="Playlist"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistFixture
{
private readonly Faker _faker = new();
private readonly PlaylistIdFixture _playlistIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="Playlist"/> domain aggregate, with pre-existing data.
/// </summary>
/// <param name="id">Optional. The Id of the playlist.</param>
/// <param name="userId">Optional. The Id of the user that owns the playlist.</param>
/// <param name="name">Optional. The name of the playlist.</param>
/// <param name="description">Optional. The description of the playlist.</param>
/// <param name="type">Optional. The kind of media the playlist holds. Defaults to the only supported kind.</param>
/// <param name="entries">Optional. The ordered entries of the playlist. Defaults to no entries.</param>
/// <param name="createdOnUtc">Optional. The date and time when the playlist was created. Defaults to a few days in the past.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the playlist was last updated.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to no value.</param>
/// <param name="includeUpdatedOnUtc">Whether the update date and time should be included, or forced to no value.</param>
/// <returns>The created <see cref="Playlist"/>.</returns>
/// <remarks>
/// The playlist is built through the rehydrating <see cref="Playlist.Create(PlaylistId, UserId, string, Optional{string}, PlaylistType, List{PlaylistEntry}, DateTime, Optional{DateTime})"/>
/// overload, so it carries no domain events and is never marked as deleted.
/// </remarks>
public Playlist Create(
PlaylistId? id = null,
UserId? userId = null,
string? name = null,
string? description = null,
PlaylistType? type = null,
IEnumerable<PlaylistEntry>? entries = null,
DateTime? createdOnUtc = null,
DateTime? updatedOnUtc = null,
bool includeDescription = true,
bool includeUpdatedOnUtc = false)
{
return Playlist.Create(
id ?? _playlistIdFixture.Create(),
userId ?? _userIdFixture.Create(),
name ?? _faker.Lorem.Sentence(3),
includeDescription ? Optional<string>.FromNullable(description ?? _faker.Lorem.Sentence()) : Optional<string>.None(),
type ?? PlaylistType.Music,
entries is null ? [] : [.. entries],
createdOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).AddMinutes(-_faker.Random.Int(0, 59)),
includeUpdatedOnUtc ? Optional<DateTime>.Some(updatedOnUtc ?? DateTime.UtcNow) : Optional<DateTime>.None()).Value;
}
/// <summary>
/// Creates multiple <see cref="Playlist"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Playlist"/> instances.</returns>
public List<Playlist> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="PlaylistEntryId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistEntryIdFixture
{
/// <summary>
/// Creates a random valid <see cref="PlaylistEntryId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the playlist entry Id.</param>
/// <returns>The created <see cref="PlaylistEntryId"/>.</returns>
public PlaylistEntryId Create(
Guid? value = null)
{
return PlaylistEntryId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="PlaylistEntryId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistEntryId"/> instances.</returns>
public List<PlaylistEntryId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.PlaylistBoundedContext.PlaylistAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="PlaylistId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistIdFixture
{
/// <summary>
/// Creates a random valid <see cref="PlaylistId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the playlist Id.</param>
/// <returns>The created <see cref="PlaylistId"/>.</returns>
public PlaylistId Create(
Guid? value = null)
{
return PlaylistId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="PlaylistId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistId"/> instances.</returns>
public List<PlaylistId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}