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

@@ -28,6 +28,7 @@ public class StubApiHttpClient : IApiHttpClient
private readonly Dictionary<string, Func<object, object>> _postResponseFactories = [];
private readonly Dictionary<string, Func<object, object>> _putResponseFactories = [];
private readonly HashSet<string> _deleteSuccessEndpoints = [];
private readonly Dictionary<string, ApiException> _deleteExceptions = [];
private BlobDataDto? _blobResponse;
/// <summary>
@@ -167,6 +168,16 @@ public class StubApiHttpClient : IApiHttpClient
_deleteSuccessEndpoints.Add(endpoint);
}
/// <summary>
/// Registers the exception thrown when the specified DELETE endpoint is called.
/// </summary>
/// <param name="endpoint">The API endpoint for which to register the exception.</param>
/// <param name="exception">The exception to throw.</param>
public void RegisterDeleteException(string endpoint, ApiException exception)
{
_deleteExceptions[endpoint] = exception;
}
/// <summary>
/// Registers the blob response returned when a blob endpoint is called.
/// </summary>
@@ -185,6 +196,7 @@ public class StubApiHttpClient : IApiHttpClient
_postResponseFactories.Clear();
_putResponseFactories.Clear();
_deleteSuccessEndpoints.Clear();
_deleteExceptions.Clear();
_blobResponse = null;
GetEndpointsCalled.Clear();
PostRequests.Clear();
@@ -245,6 +257,8 @@ public class StubApiHttpClient : IApiHttpClient
public Task DeleteAsync(string endpoint, CancellationToken cancellationToken = default)
{
DeleteEndpointsCalled.Add(endpoint);
if (_deleteExceptions.TryGetValue(endpoint, out ApiException? exception))
throw exception;
if (_deleteSuccessEndpoints.Contains(endpoint))
return Task.CompletedTask;
throw new ApiException(null, System.Net.HttpStatusCode.InternalServerError, endpoint);
@@ -15,7 +15,7 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Api;
[ExcludeFromCodeCoverage]
public class TestApiHttpMessageHandler : HttpMessageHandler
{
private readonly Func<HttpRequestMessage, HttpResponseMessage> _responseFactory;
private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> _responseFactory;
/// <summary>
/// Gets the list of requests that were sent through this handler.
@@ -27,11 +27,25 @@ public class TestApiHttpMessageHandler : HttpMessageHandler
/// </summary>
public List<string?> RequestBodies { get; } = [];
/// <summary>
/// Gets the cancellation tokens the requests were sent with.
/// </summary>
public List<CancellationToken> CancellationTokens { get; } = [];
/// <summary>
/// Initializes a new instance of the <see cref="TestApiHttpMessageHandler"/> class.
/// </summary>
/// <param name="responseFactory">The factory that produces the response for a given request.</param>
public TestApiHttpMessageHandler(Func<HttpRequestMessage, HttpResponseMessage> responseFactory)
{
_responseFactory = (request, cancellationToken) => Task.FromResult(responseFactory(request));
}
/// <summary>
/// Initializes a new instance of the <see cref="TestApiHttpMessageHandler"/> class.
/// </summary>
/// <param name="responseFactory">The asynchronous factory that produces the response for a given request and cancellation token.</param>
public TestApiHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> responseFactory)
{
_responseFactory = responseFactory;
}
@@ -45,7 +59,8 @@ public class TestApiHttpMessageHandler : HttpMessageHandler
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Requests.Add(request);
CancellationTokens.Add(cancellationToken);
RequestBodies.Add(request.Content is null ? null : await request.Content.ReadAsStringAsync(cancellationToken));
return await Task.FromResult(_responseFactory(request));
return await _responseFactory(request, cancellationToken);
}
}
@@ -0,0 +1,100 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Api;
/// <summary>
/// <see cref="HttpContent"/> test double that exposes whether the client buffered the content before handing it to the caller,
/// whether the content was disposed, and whether obtaining its stream is allowed to fail.
/// </summary>
[ExcludeFromCodeCoverage]
public sealed class TrackingStreamContent : HttpContent
{
private readonly byte[] _contentBytes;
private readonly MemoryStream _contentStream;
private readonly bool _shouldFailStreamCreation;
/// <summary>
/// Gets a value indicating whether the content was buffered by the client before it was handed to the caller.
/// </summary>
public bool WasBufferedByClient { get; private set; }
/// <summary>
/// Gets a value indicating whether the content was disposed.
/// </summary>
public bool IsDisposed { get; private set; }
/// <summary>
/// Gets the stream the content hands over when it is read without being buffered first.
/// </summary>
public Stream ContentStream => _contentStream;
/// <summary>
/// Initializes a new instance of the <see cref="TrackingStreamContent"/> class.
/// </summary>
/// <param name="contentBytes">The bytes of the content.</param>
/// <param name="mediaType">The media type the content declares.</param>
/// <param name="shouldFailStreamCreation">Whether obtaining the content stream should fail.</param>
public TrackingStreamContent(byte[] contentBytes, string mediaType = "application/octet-stream", bool shouldFailStreamCreation = false)
{
_contentBytes = contentBytes;
_contentStream = new MemoryStream(contentBytes);
_shouldFailStreamCreation = shouldFailStreamCreation;
Headers.ContentType = new MediaTypeHeaderValue(mediaType);
}
/// <summary>
/// Writes the content to the provided stream, recording that the client buffered it.
/// </summary>
/// <param name="stream">The stream the content is written to.</param>
/// <param name="context">The transport context of the serialization, if any.</param>
/// <returns>A task that represents the asynchronous serialization.</returns>
protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context)
{
WasBufferedByClient = true;
return stream.WriteAsync(_contentBytes, 0, _contentBytes.Length);
}
/// <summary>
/// Hands over the known content stream without buffering the content first.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>The content stream.</returns>
/// <exception cref="InvalidOperationException">Thrown when the content is configured to fail obtaining its stream.</exception>
protected override Task<Stream> CreateContentReadStreamAsync(CancellationToken cancellationToken)
{
if (_shouldFailStreamCreation)
throw new InvalidOperationException("The content stream cannot be obtained.");
return Task.FromResult<Stream>(_contentStream);
}
/// <summary>
/// Computes the length of the content.
/// </summary>
/// <param name="length">The length of the content in bytes.</param>
/// <returns>Always <see langword="true"/>.</returns>
protected override bool TryComputeLength(out long length)
{
length = _contentBytes.Length;
return true;
}
/// <summary>
/// Disposes the content, recording that it was disposed.
/// </summary>
/// <param name="disposing">Whether the content is being disposed.</param>
protected override void Dispose(bool disposing)
{
if (disposing)
IsDisposed = true;
base.Dispose(disposing);
}
}
@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Playlists;
using Lumina.Presentation.Web.Common.Enums.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Playlists;
/// <summary>
/// Fixture class for the <see cref="PlaylistDetailsDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistDetailsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="PlaylistDetailsDto"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional Id of the playlist.</param>
/// <param name="name">Optional name of the playlist.</param>
/// <param name="description">Optional description of the playlist.</param>
/// <param name="type">Optional kind of media the playlist holds.</param>
/// <param name="updatedOnUtc">Optional date and time when the playlist was last updated.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeUpdatedOnUtc">Whether the last update date should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="PlaylistDetailsDto"/> instance.</returns>
public PlaylistDetailsDto Create(
Guid? id = null,
string? name = null,
string? description = null,
PlaylistType? type = null,
DateTime? updatedOnUtc = null,
bool includeDescription = true,
bool includeUpdatedOnUtc = true)
{
DateTime resolvedUpdatedOnUtc = DateTime.SpecifyKind(updatedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 24)), DateTimeKind.Utc);
return new PlaylistDetailsDto(
Id: id ?? _faker.Random.Guid(),
Name: name ?? _faker.Lorem.Sentence(3),
Description: includeDescription ? (description ?? _faker.Lorem.Sentence(5)) : null,
Type: type ?? PlaylistType.Music,
UpdatedOnUtc: includeUpdatedOnUtc ? resolvedUpdatedOnUtc : null
);
}
/// <summary>
/// Creates multiple <see cref="PlaylistDetailsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistDetailsDto"/> instances.</returns>
public List<PlaylistDetailsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Playlists;
/// <summary>
/// Fixture class for the <see cref="PlaylistEntriesAddedDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistEntriesAddedDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="PlaylistEntriesAddedDto"/> instance with randomized test data.
/// </summary>
/// <param name="playlistId">Optional Id of the playlist the entries were added to.</param>
/// <param name="addedCount">Optional number of entries that were appended.</param>
/// <param name="updatedOnUtc">Optional date and time when the playlist was last updated.</param>
/// <param name="includeUpdatedOnUtc">Whether the last update date should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="PlaylistEntriesAddedDto"/> instance.</returns>
public PlaylistEntriesAddedDto Create(
Guid? playlistId = null,
int? addedCount = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = true)
{
DateTime resolvedUpdatedOnUtc = DateTime.SpecifyKind(updatedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 24)), DateTimeKind.Utc);
return new PlaylistEntriesAddedDto(
PlaylistId: playlistId ?? _faker.Random.Guid(),
AddedCount: addedCount ?? _faker.Random.Int(0, 1_000),
UpdatedOnUtc: includeUpdatedOnUtc ? resolvedUpdatedOnUtc : null
);
}
/// <summary>
/// Creates multiple <see cref="PlaylistEntriesAddedDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistEntriesAddedDto"/> instances.</returns>
public List<PlaylistEntriesAddedDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Playlists;
/// <summary>
/// Fixture class for the <see cref="PlaylistEntryAddedDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistEntryAddedDtoFixture
{
private readonly Faker _faker = new();
private readonly PlaylistEntryDtoFixture _playlistEntryDtoFixture = new();
/// <summary>
/// Creates a new <see cref="PlaylistEntryAddedDto"/> instance with randomized test data.
/// </summary>
/// <param name="playlistId">Optional Id of the playlist the entry was added to.</param>
/// <param name="entry">Optional added entry.</param>
/// <param name="updatedOnUtc">Optional date and time when the playlist was last updated.</param>
/// <param name="includeUpdatedOnUtc">Whether the last update date should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="PlaylistEntryAddedDto"/> instance.</returns>
public PlaylistEntryAddedDto Create(
Guid? playlistId = null,
PlaylistEntryDto? entry = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = true)
{
DateTime resolvedUpdatedOnUtc = DateTime.SpecifyKind(updatedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 24)), DateTimeKind.Utc);
return new PlaylistEntryAddedDto(
PlaylistId: playlistId ?? _faker.Random.Guid(),
Entry: entry ?? _playlistEntryDtoFixture.Create(),
UpdatedOnUtc: includeUpdatedOnUtc ? resolvedUpdatedOnUtc : null
);
}
/// <summary>
/// Creates multiple <see cref="PlaylistEntryAddedDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistEntryAddedDto"/> instances.</returns>
public List<PlaylistEntryAddedDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Playlists;
/// <summary>
/// Fixture class for the <see cref="PlaylistEntryMovedDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistEntryMovedDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="PlaylistEntryMovedDto"/> instance with randomized test data.
/// </summary>
/// <param name="playlistId">Optional Id of the playlist whose entry was moved.</param>
/// <param name="entryId">Optional Id of the moved entry.</param>
/// <param name="position">Optional new zero based position of the entry.</param>
/// <param name="updatedOnUtc">Optional date and time when the playlist was last updated.</param>
/// <param name="includeUpdatedOnUtc">Whether the last update date should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="PlaylistEntryMovedDto"/> instance.</returns>
public PlaylistEntryMovedDto Create(
Guid? playlistId = null,
Guid? entryId = null,
int? position = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = true)
{
DateTime resolvedUpdatedOnUtc = DateTime.SpecifyKind(updatedOnUtc ?? DateTime.UtcNow.AddHours(-_faker.Random.Int(1, 24)), DateTimeKind.Utc);
return new PlaylistEntryMovedDto(
PlaylistId: playlistId ?? _faker.Random.Guid(),
EntryId: entryId ?? _faker.Random.Guid(),
Position: position ?? _faker.Random.Int(0, 1_000),
UpdatedOnUtc: includeUpdatedOnUtc ? resolvedUpdatedOnUtc : null
);
}
/// <summary>
/// Creates multiple <see cref="PlaylistEntryMovedDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistEntryMovedDto"/> instances.</returns>
public List<PlaylistEntryMovedDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Playlists;
using Lumina.Presentation.Web.Common.Enums.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Playlists;
/// <summary>
/// Fixture class for the <see cref="PlaylistSummaryDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaylistSummaryDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="PlaylistSummaryDto"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional Id of the playlist.</param>
/// <param name="name">Optional name of the playlist.</param>
/// <param name="description">Optional description of the playlist.</param>
/// <param name="type">Optional kind of media the playlist holds.</param>
/// <param name="entryCount">Optional number of entries of the playlist.</param>
/// <param name="createdOnUtc">Optional date and time when the playlist was created.</param>
/// <param name="updatedOnUtc">Optional date and time when the playlist was last updated.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeUpdatedOnUtc">Whether the last update date should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="PlaylistSummaryDto"/> instance.</returns>
public PlaylistSummaryDto Create(
Guid? id = null,
string? name = null,
string? description = null,
PlaylistType? type = null,
int? entryCount = null,
DateTime? createdOnUtc = null,
DateTime? updatedOnUtc = null,
bool includeDescription = true,
bool includeUpdatedOnUtc = true)
{
DateTime resolvedCreatedOnUtc = DateTime.SpecifyKind(createdOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)), DateTimeKind.Utc);
DateTime resolvedUpdatedOnUtc = DateTime.SpecifyKind(updatedOnUtc ?? resolvedCreatedOnUtc.AddHours(_faker.Random.Int(1, 24)), DateTimeKind.Utc);
return new PlaylistSummaryDto(
Id: id ?? _faker.Random.Guid(),
Name: name ?? _faker.Lorem.Sentence(3),
Description: includeDescription ? (description ?? _faker.Lorem.Sentence(5)) : null,
Type: type ?? PlaylistType.Music,
EntryCount: entryCount ?? _faker.Random.Int(0, 1_000),
CreatedOnUtc: resolvedCreatedOnUtc,
UpdatedOnUtc: includeUpdatedOnUtc ? resolvedUpdatedOnUtc : null
);
}
/// <summary>
/// Creates multiple <see cref="PlaylistSummaryDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PlaylistSummaryDto"/> instances.</returns>
public List<PlaylistSummaryDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -22,14 +22,16 @@ public class ThemeTemplateResponseDtoFixture
/// </summary>
/// <param name="theme">Optional theme the template belongs to.</param>
/// <param name="template">Optional sanitized template content.</param>
/// <param name="includeTemplate">Whether the template content should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="ThemeTemplateResponseDto"/> instance.</returns>
public ThemeTemplateResponseDto Create(
ThemeResponseDto? theme = null,
string? template = null)
string? template = null,
bool includeTemplate = true)
{
return new ThemeTemplateResponseDto(
Theme: theme ?? _themeResponseDtoFixture.Create(),
Template: template ?? _faker.Lorem.Paragraph()
Template: includeTemplate ? (template ?? _faker.Lorem.Paragraph()) : null!
);
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
/// <summary>
/// Fixture class for the <see cref="PlaybackStateDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PlaybackStateDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PlaybackStateDto"/>.
/// </summary>
/// <param name="volume">Optional. The last volume the player reported, as a value between 0 and 1.</param>
/// <param name="isMuted">Optional. The last mute state the player reported.</param>
/// <param name="includeVolume">Whether the volume should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeIsMuted">Whether the mute state should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="PlaybackStateDto"/>.</returns>
public PlaybackStateDto Create(
double? volume = null,
bool? isMuted = null,
bool includeVolume = true,
bool includeIsMuted = true)
{
return new PlaybackStateDto
{
Volume = includeVolume ? volume ?? _faker.Random.Double(0, 1) : null,
IsMuted = includeIsMuted ? isMuted ?? _faker.Random.Bool() : null
};
}
/// <summary>
/// Creates a list of <see cref="PlaybackStateDto"/> instances.
/// </summary>
/// <param name="count">Number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PlaybackStateDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="AddPlaylistEntriesRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddPlaylistEntriesRequestFixture
{
/// <summary>
/// Creates a new <see cref="AddPlaylistEntriesRequest"/> instance with randomized test data.
/// </summary>
/// <param name="trackIds">Optional Ids of the tracks to add, in order.</param>
/// <param name="trackCount">Optional number of random track Ids to generate when <paramref name="trackIds"/> is not supplied.</param>
/// <param name="includeTrackIds">Whether the track Ids should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="AddPlaylistEntriesRequest"/> instance.</returns>
public AddPlaylistEntriesRequest Create(
List<Guid>? trackIds = null,
int trackCount = 3,
bool includeTrackIds = true)
{
return new AddPlaylistEntriesRequest(
TrackIds: includeTrackIds ? (trackIds ?? CreateRandomTrackIds(trackCount)) : null);
}
/// <summary>
/// Creates multiple <see cref="AddPlaylistEntriesRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="AddPlaylistEntriesRequest"/> instances.</returns>
public List<AddPlaylistEntriesRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates the requested number of distinct random track Ids.
/// </summary>
/// <param name="count">The number of track Ids to create.</param>
/// <returns>The created track Ids.</returns>
private static List<Guid> CreateRandomTrackIds(int count)
{
return [.. Enumerable.Range(0, count).Select(_ => Guid.NewGuid())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="AddPlaylistEntryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddPlaylistEntryRequestFixture
{
/// <summary>
/// Creates a new <see cref="AddPlaylistEntryRequest"/> instance with randomized test data.
/// </summary>
/// <param name="trackId">Optional Id of the track to add.</param>
/// <param name="includeTrackId">Whether the track Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="AddPlaylistEntryRequest"/> instance.</returns>
public AddPlaylistEntryRequest Create(
Guid? trackId = null,
bool includeTrackId = true)
{
return new AddPlaylistEntryRequest(
TrackId: includeTrackId ? (trackId ?? Guid.NewGuid()) : null);
}
/// <summary>
/// Creates multiple <see cref="AddPlaylistEntryRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="AddPlaylistEntryRequest"/> instances.</returns>
public List<AddPlaylistEntryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="AddPlaylistScopeEntriesRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddPlaylistScopeEntriesRequestFixture
{
/// <summary>
/// Creates a new <see cref="AddPlaylistScopeEntriesRequest"/> instance with randomized test data.
/// </summary>
/// <param name="libraryId">Optional Id of the music library the scope belongs to.</param>
/// <param name="artistId">Optional Id of the artist the scope is limited to.</param>
/// <param name="albumId">Optional Id of the album the scope is limited to.</param>
/// <param name="includeArtistId">Whether the artist Id should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeAlbumId">Whether the album Id should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="AddPlaylistScopeEntriesRequest"/> instance.</returns>
public AddPlaylistScopeEntriesRequest Create(
Guid? libraryId = null,
Guid? artistId = null,
Guid? albumId = null,
bool includeArtistId = true,
bool includeAlbumId = true)
{
return new AddPlaylistScopeEntriesRequest(
LibraryId: libraryId ?? Guid.NewGuid(),
ArtistId: includeArtistId ? (artistId ?? Guid.NewGuid()) : null,
AlbumId: includeAlbumId ? (albumId ?? Guid.NewGuid()) : null);
}
/// <summary>
/// Creates multiple <see cref="AddPlaylistScopeEntriesRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="AddPlaylistScopeEntriesRequest"/> instances.</returns>
public List<AddPlaylistScopeEntriesRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Enums.Playlists;
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="CreatePlaylistRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class CreatePlaylistRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="CreatePlaylistRequest"/> instance with randomized test data.
/// </summary>
/// <param name="name">Optional name of the playlist.</param>
/// <param name="description">Optional description of the playlist.</param>
/// <param name="type">Optional kind of media the playlist holds.</param>
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeType">Whether the media type should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="CreatePlaylistRequest"/> instance.</returns>
public CreatePlaylistRequest Create(
string? name = null,
string? description = null,
PlaylistType? type = null,
bool includeName = true,
bool includeDescription = true,
bool includeType = true)
{
return new CreatePlaylistRequest(
Name: includeName ? (name ?? _faker.Lorem.Sentence(3)) : null,
Description: includeDescription ? (description ?? _faker.Lorem.Sentence(5)) : null,
Type: includeType ? (type ?? PlaylistType.Music) : null);
}
/// <summary>
/// Creates multiple <see cref="CreatePlaylistRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CreatePlaylistRequest"/> instances.</returns>
public List<CreatePlaylistRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="MovePlaylistEntryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MovePlaylistEntryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="MovePlaylistEntryRequest"/> instance with randomized test data.
/// </summary>
/// <param name="targetPosition">Optional new zero based position of the entry.</param>
/// <param name="includeTargetPosition">Whether the target position should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="MovePlaylistEntryRequest"/> instance.</returns>
public MovePlaylistEntryRequest Create(
int? targetPosition = null,
bool includeTargetPosition = true)
{
return new MovePlaylistEntryRequest(
TargetPosition: includeTargetPosition ? (targetPosition ?? _faker.Random.Int(0, 1_000)) : null);
}
/// <summary>
/// Creates multiple <see cref="MovePlaylistEntryRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MovePlaylistEntryRequest"/> instances.</returns>
public List<MovePlaylistEntryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,47 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Requests.Playlists;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Playlists;
/// <summary>
/// Fixture class for the <see cref="UpdatePlaylistRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdatePlaylistRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="UpdatePlaylistRequest"/> instance with randomized test data.
/// </summary>
/// <param name="name">Optional name of the playlist.</param>
/// <param name="description">Optional description of the playlist.</param>
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeDescription">Whether the description should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="UpdatePlaylistRequest"/> instance.</returns>
public UpdatePlaylistRequest Create(
string? name = null,
string? description = null,
bool includeName = true,
bool includeDescription = true)
{
return new UpdatePlaylistRequest(
Name: includeName ? (name ?? _faker.Lorem.Sentence(3)) : null,
Description: includeDescription ? (description ?? _faker.Lorem.Sentence(5)) : null);
}
/// <summary>
/// Creates multiple <see cref="UpdatePlaylistRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UpdatePlaylistRequest"/> instances.</returns>
public List<UpdatePlaylistRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}