mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Implements tests for commit 525ac1348d
Covers the favorites feature and the playlist and favorite pagination changes with unit, integration and security tests, and fixtures for the new request, response, DTO and entity types. Also fixes the issues found while covering the commit: declares FavoriteMediaKind.None as the default value and rejects it in every favorite operation; queues the favorite added domain event only after the persisted favorite is read back; and preserves the private, no-store cache header on view pages after the antiforgery and session middlewares overwrite it.
This commit is contained in:
1 parent
468f1846f1
commit
394f6b510c
135 files changed
+19167
-13
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteItemDisplayDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteItemDisplayDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteItemDisplayDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the media item.</param>
|
||||
/// <param name="title">Optional. The title of the media item.</param>
|
||||
/// <param name="collectionId">Optional. The Id of the collection that contains the media item.</param>
|
||||
/// <param name="collectionTitle">Optional. The title of the collection that contains the media item.</param>
|
||||
/// <param name="creatorId">Optional. The Id of the creator of the media item.</param>
|
||||
/// <param name="creatorName">Optional. The name of the creator of the media item.</param>
|
||||
/// <param name="coverPath">Optional. The path of the cover art of the media item.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="FavoriteItemDisplayDto"/>.</returns>
|
||||
public FavoriteItemDisplayDto Create(
|
||||
Guid? libraryId = null,
|
||||
string? title = null,
|
||||
Guid? collectionId = null,
|
||||
string? collectionTitle = null,
|
||||
Guid? creatorId = null,
|
||||
string? creatorName = null,
|
||||
string? coverPath = null,
|
||||
bool includeCoverPath = true)
|
||||
{
|
||||
return new FavoriteItemDisplayDto(
|
||||
libraryId ?? _faker.Random.Guid(),
|
||||
title ?? _faker.Lorem.Sentence(3),
|
||||
collectionId ?? _faker.Random.Guid(),
|
||||
collectionTitle ?? _faker.Lorem.Sentence(3),
|
||||
creatorId ?? _faker.Random.Guid(),
|
||||
creatorName ?? _faker.Name.FullName(),
|
||||
includeCoverPath ? (coverPath ?? $"/covers/{_faker.Random.Guid()}.jpg") : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FavoriteItemDisplayDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteItemDisplayDto"/> instances.</returns>
|
||||
public List<FavoriteItemDisplayDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Favorites;
|
||||
using Lumina.Application.Common.DTO.Favorites;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Favorites;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteItemDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteItemDtoFixture
|
||||
{
|
||||
private readonly FavoriteEntityFixture _favoriteEntityFixture = new();
|
||||
private readonly FavoriteItemDisplayDtoFixture _favoriteItemDisplayDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteItemDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="favorite">Optional. The stored favorite.</param>
|
||||
/// <param name="display">Optional. The display data of the referenced media item.</param>
|
||||
/// <param name="includeDisplay">Whether the display data should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="FavoriteItemDto"/>.</returns>
|
||||
public FavoriteItemDto Create(
|
||||
FavoriteEntity? favorite = null,
|
||||
FavoriteItemDisplayDto? display = null,
|
||||
bool includeDisplay = true)
|
||||
{
|
||||
return new FavoriteItemDto(
|
||||
favorite ?? _favoriteEntityFixture.Create(),
|
||||
includeDisplay ? (display ?? _favoriteItemDisplayDtoFixture.Create()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FavoriteItemDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteItemDto"/> instances.</returns>
|
||||
public List<FavoriteItemDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PlaylistDetailsDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PlaylistDetailsDtoFixture
|
||||
{
|
||||
private readonly PlaylistEntityFixture _playlistEntityFixture = new();
|
||||
private readonly PlaylistEntryDtoFixture _playlistEntryDtoFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<PlaylistEntryDto> _paginatedResultDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PlaylistDetailsDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="playlist">Optional. The stored playlist.</param>
|
||||
/// <param name="entries">Optional. The requested page of entries. Defaults to a page of random entries.</param>
|
||||
/// <returns>The created <see cref="PlaylistDetailsDto"/>.</returns>
|
||||
public PlaylistDetailsDto Create(
|
||||
PlaylistEntity? playlist = null,
|
||||
PaginatedResultDto<PlaylistEntryDto>? entries = null)
|
||||
{
|
||||
List<PlaylistEntryDto> entryDtos = _playlistEntryDtoFixture.CreateMany();
|
||||
return new PlaylistDetailsDto(
|
||||
playlist ?? _playlistEntityFixture.Create(),
|
||||
entries ?? _paginatedResultDtoFixture.Create(data: entryDtos, count: entryDtos.Count));
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PlaylistEntryDisplayDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PlaylistEntryDisplayDtoFixture
|
||||
{
|
||||
private const int MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PlaylistEntryDisplayDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="trackId">Optional. The Id of the track.</param>
|
||||
/// <param name="trackTitle">Optional. The title of the track.</param>
|
||||
/// <param name="durationInSeconds">Optional. The duration of the track, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the track.</param>
|
||||
/// <param name="albumId">Optional. The Id of the album that contains the track.</param>
|
||||
/// <param name="albumTitle">Optional. The title of the album that contains the track.</param>
|
||||
/// <param name="artistId">Optional. The Id of the artist that produced the track.</param>
|
||||
/// <param name="artistName">Optional. The name of the artist that produced the track.</param>
|
||||
/// <param name="coverPath">Optional. The path of the cover art of the album.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="PlaylistEntryDisplayDto"/>.</returns>
|
||||
public PlaylistEntryDisplayDto Create(
|
||||
Guid? trackId = null,
|
||||
string? trackTitle = null,
|
||||
int? durationInSeconds = null,
|
||||
Guid? libraryId = null,
|
||||
Guid? albumId = null,
|
||||
string? albumTitle = null,
|
||||
Guid? artistId = null,
|
||||
string? artistName = null,
|
||||
string? coverPath = null,
|
||||
bool includeCoverPath = true)
|
||||
{
|
||||
return new PlaylistEntryDisplayDto(
|
||||
trackId ?? _faker.Random.Guid(),
|
||||
trackTitle ?? _faker.Lorem.Sentence(3),
|
||||
durationInSeconds ?? _faker.Random.Int(0, MAXIMUM_DURATION_SECONDS),
|
||||
libraryId ?? _faker.Random.Guid(),
|
||||
albumId ?? _faker.Random.Guid(),
|
||||
albumTitle ?? _faker.Lorem.Sentence(3),
|
||||
artistId ?? _faker.Random.Guid(),
|
||||
artistName ?? _faker.Name.FullName(),
|
||||
includeCoverPath ? (coverPath ?? $"/covers/{_faker.Random.Guid()}.jpg") : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PlaylistEntryDisplayDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="PlaylistEntryDisplayDto"/> instances.</returns>
|
||||
public List<PlaylistEntryDisplayDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Playlists;
|
||||
using Lumina.Application.Common.DTO.Playlists;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Playlists;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PlaylistEntryDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PlaylistEntryDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly PlaylistEntryEntityFixture _playlistEntryEntityFixture = new();
|
||||
private readonly PlaylistEntryDisplayDtoFixture _playlistEntryDisplayDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PlaylistEntryDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="entry">Optional. The stored playlist entry.</param>
|
||||
/// <param name="display">Optional. The display data of the referenced media item.</param>
|
||||
/// <param name="displayPosition">Optional. The dense zero based position shown to the client.</param>
|
||||
/// <param name="includeDisplay">Whether the display data should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="PlaylistEntryDto"/>.</returns>
|
||||
public PlaylistEntryDto Create(
|
||||
PlaylistEntryEntity? entry = null,
|
||||
PlaylistEntryDisplayDto? display = null,
|
||||
int? displayPosition = null,
|
||||
bool includeDisplay = true)
|
||||
{
|
||||
return new PlaylistEntryDto(
|
||||
entry ?? _playlistEntryEntityFixture.Create(),
|
||||
includeDisplay ? (display ?? _playlistEntryDisplayDtoFixture.Create()) : null,
|
||||
displayPosition ?? _faker.Random.Int(0, 1_000));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PlaylistEntryDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="PlaylistEntryDto"/> instances.</returns>
|
||||
public List<PlaylistEntryDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Favorites;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly FavoriteMediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
FavoriteMediaKind.MusicArtist,
|
||||
FavoriteMediaKind.MusicAlbum,
|
||||
FavoriteMediaKind.MusicTrack,
|
||||
FavoriteMediaKind.Book
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the favorite.</param>
|
||||
/// <param name="userId">Optional. The Id of the user that owns the favorite.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of the favorited media item. Defaults to a random supported kind.</param>
|
||||
/// <param name="mediaItemId">Optional. The Id of the favorited media item.</param>
|
||||
/// <param name="createdOnUtc">Optional. The date and time when the favorite was created. Defaults to a moment in the past.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the row.</param>
|
||||
/// <param name="updatedOnUtc">Optional. The date and time when the favorite was last updated. Defaults to a moment at or after the creation date.</param>
|
||||
/// <param name="updatedBy">Optional. The Id of the user that last updated the row.</param>
|
||||
/// <param name="includeUpdatedOnUtc">Whether the update time should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeUpdatedBy">Whether the updating user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="FavoriteEntity"/>.</returns>
|
||||
public FavoriteEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? userId = null,
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
Guid? mediaItemId = null,
|
||||
DateTime? createdOnUtc = null,
|
||||
Guid? createdBy = null,
|
||||
DateTime? updatedOnUtc = null,
|
||||
Guid? updatedBy = null,
|
||||
bool includeUpdatedOnUtc = true,
|
||||
bool includeUpdatedBy = true)
|
||||
{
|
||||
DateTime resolvedCreatedOnUtc = createdOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).AddMinutes(-_faker.Random.Int(0, 59));
|
||||
|
||||
return new FavoriteEntity
|
||||
{
|
||||
Id = id ?? _faker.Random.Guid(),
|
||||
UserId = userId ?? _faker.Random.Guid(),
|
||||
MediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
MediaItemId = mediaItemId ?? _faker.Random.Guid(),
|
||||
CreatedOnUtc = resolvedCreatedOnUtc,
|
||||
CreatedBy = createdBy ?? _faker.Random.Guid(),
|
||||
UpdatedOnUtc = includeUpdatedOnUtc ? (updatedOnUtc ?? resolvedCreatedOnUtc.AddMinutes(_faker.Random.Int(0, 120))) : null,
|
||||
UpdatedBy = includeUpdatedBy ? (updatedBy ?? _faker.Random.Guid()) : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FavoriteEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteEntity"/> instances.</returns>
|
||||
public List<FavoriteEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Favorites.Commands.AddFavorite;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Favorites.Commands.AddFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddFavoriteCommand"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddFavoriteCommandFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AddFavoriteCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The kind of the media item to favorite. Defaults to a supported kind.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the media item to favorite.</param>
|
||||
/// <param name="includeMediaKind">Whether the media kind should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeMediaItemId">Whether the media item Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AddFavoriteCommand"/>.</returns>
|
||||
public AddFavoriteCommand Create(
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
Guid? mediaItemId = null,
|
||||
bool includeMediaKind = true,
|
||||
bool includeMediaItemId = true)
|
||||
{
|
||||
return new AddFavoriteCommand(
|
||||
includeMediaKind ? (mediaKind ?? FavoriteMediaKind.MusicTrack) : null,
|
||||
includeMediaItemId ? (mediaItemId ?? _faker.Random.Guid()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AddFavoriteCommand"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="AddFavoriteCommand"/> instances.</returns>
|
||||
public List<AddFavoriteCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Favorites.Commands.RemoveFavorite;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Favorites.Commands.RemoveFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RemoveFavoriteCommand"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RemoveFavoriteCommandFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="RemoveFavoriteCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The name of the kind of the favorited media item. Defaults to the name of a supported kind.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the favorited media item.</param>
|
||||
/// <param name="includeMediaKind">Whether the media kind should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeMediaItemId">Whether the media item Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="RemoveFavoriteCommand"/>.</returns>
|
||||
public RemoveFavoriteCommand Create(
|
||||
string? mediaKind = null,
|
||||
string? mediaItemId = null,
|
||||
bool includeMediaKind = true,
|
||||
bool includeMediaItemId = true)
|
||||
{
|
||||
return new RemoveFavoriteCommand(
|
||||
includeMediaKind ? (mediaKind ?? nameof(FavoriteMediaKind.MusicTrack)) : null,
|
||||
includeMediaItemId ? (mediaItemId ?? _faker.Random.Guid().ToString()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="RemoveFavoriteCommand"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="RemoveFavoriteCommand"/> instances.</returns>
|
||||
public List<RemoveFavoriteCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Favorites.Queries.GetFavoriteStatus;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Favorites.Queries.GetFavoriteStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetFavoriteStatusQuery"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFavoriteStatusQueryFixture
|
||||
{
|
||||
private const int DEFAULT_MEDIA_ITEM_COUNT = 3;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetFavoriteStatusQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The kind of the media items to check. Defaults to a supported kind.</param>
|
||||
/// <param name="mediaItemIds">Optional. The unique identifiers of the media items to check. Defaults to a bounded list of random Ids.</param>
|
||||
/// <param name="includeMediaKind">Whether the media kind should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeMediaItemIds">Whether the media item Ids should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetFavoriteStatusQuery"/>.</returns>
|
||||
public GetFavoriteStatusQuery Create(
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
IReadOnlyList<Guid>? mediaItemIds = null,
|
||||
bool includeMediaKind = true,
|
||||
bool includeMediaItemIds = true)
|
||||
{
|
||||
return new GetFavoriteStatusQuery(
|
||||
includeMediaKind ? (mediaKind ?? FavoriteMediaKind.MusicTrack) : null,
|
||||
includeMediaItemIds ? (mediaItemIds ?? CreateRandomMediaItemIds()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetFavoriteStatusQuery"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="GetFavoriteStatusQuery"/> instances.</returns>
|
||||
public List<GetFavoriteStatusQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a bounded list of random media item Ids.
|
||||
/// </summary>
|
||||
/// <returns>The created list of media item Ids.</returns>
|
||||
private List<Guid> CreateRandomMediaItemIds()
|
||||
{
|
||||
return [.. Enumerable.Range(0, DEFAULT_MEDIA_ITEM_COUNT).Select(_ => _faker.Random.Guid())];
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Favorites.Queries.GetFavorites;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Favorites.Queries.GetFavorites;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetFavoritesQuery"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFavoritesQueryFixture
|
||||
{
|
||||
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetFavoritesQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="mediaKind">Optional. The kind of media item to restrict the favorites to. Defaults to a supported kind.</param>
|
||||
/// <param name="paginationData">Optional. The object containing the requested pagination data. Defaults to a random page.</param>
|
||||
/// <param name="includeMediaKind">Whether the media kind should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePaginationData">Whether the pagination data should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetFavoritesQuery"/>.</returns>
|
||||
public GetFavoritesQuery Create(
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
PaginationDataDto? paginationData = null,
|
||||
bool includeMediaKind = true,
|
||||
bool includePaginationData = true)
|
||||
{
|
||||
return new GetFavoritesQuery(
|
||||
includeMediaKind ? (mediaKind ?? FavoriteMediaKind.MusicTrack) : null,
|
||||
includePaginationData ? (paginationData ?? _paginationDataDtoFixture.Create()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetFavoritesQuery"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="GetFavoritesQuery"/> instances.</returns>
|
||||
public List<GetFavoritesQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Playlists.Commands.CreatePlaylist;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Playlists.Commands.CreatePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CreatePlaylistCommand"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CreatePlaylistCommandFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="CreatePlaylistCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the playlist.</param>
|
||||
/// <param name="description">Optional. The optional 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="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>The created <see cref="CreatePlaylistCommand"/>.</returns>
|
||||
public CreatePlaylistCommand Create(
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
PlaylistType? type = null,
|
||||
bool includeDescription = true,
|
||||
bool includeType = true)
|
||||
{
|
||||
return new CreatePlaylistCommand(
|
||||
name ?? _faker.Lorem.Sentence(3),
|
||||
includeDescription ? (description ?? _faker.Lorem.Sentence()) : null,
|
||||
includeType ? (type ?? PlaylistType.Music) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="CreatePlaylistCommand"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="CreatePlaylistCommand"/> instances.</returns>
|
||||
public List<CreatePlaylistCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Playlists.Queries.GetPlaylist;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Playlists.Queries.GetPlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPlaylistQuery"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPlaylistQueryFixture
|
||||
{
|
||||
private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetPlaylistQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="playlistId">Optional. The unique identifier of the playlist. Defaults to a random Guid.</param>
|
||||
/// <param name="paginationData">Optional. The object containing the requested pagination data. Defaults to a random page.</param>
|
||||
/// <param name="includePlaylistId">Whether the playlist Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePaginationData">Whether the pagination data should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetPlaylistQuery"/>.</returns>
|
||||
public GetPlaylistQuery Create(
|
||||
string? playlistId = null,
|
||||
PaginationDataDto? paginationData = null,
|
||||
bool includePlaylistId = true,
|
||||
bool includePaginationData = true)
|
||||
{
|
||||
return new GetPlaylistQuery(
|
||||
includePlaylistId ? (playlistId ?? Guid.NewGuid().ToString()) : null,
|
||||
includePaginationData ? (paginationData ?? _paginationDataDtoFixture.Create()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetPlaylistQuery"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="GetPlaylistQuery"/> instances.</returns>
|
||||
public List<GetPlaylistQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user