mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21: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
+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())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user