mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15: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
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.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())];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.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())];
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteAddedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteAddedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly FavoriteIdFixture _favoriteIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly FavoriteMediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
FavoriteMediaKind.MusicArtist,
|
||||
FavoriteMediaKind.MusicAlbum,
|
||||
FavoriteMediaKind.MusicTrack,
|
||||
FavoriteMediaKind.Book
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteAddedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="favoriteId">Optional. The unique identifier of the favorite.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that favorited the media item.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the favorited media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of the favorited media item. Defaults to a random supported kind.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="FavoriteAddedDomainEvent"/>.</returns>
|
||||
public FavoriteAddedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
FavoriteId? favoriteId = null,
|
||||
UserId? userId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new FavoriteAddedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
favoriteId ?? _favoriteIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="FavoriteAddedDomainEvent"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteAddedDomainEvent"/> instances.</returns>
|
||||
public List<FavoriteAddedDomainEvent> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteRemovedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteRemovedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly FavoriteIdFixture _favoriteIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly FavoriteMediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
FavoriteMediaKind.MusicArtist,
|
||||
FavoriteMediaKind.MusicAlbum,
|
||||
FavoriteMediaKind.MusicTrack,
|
||||
FavoriteMediaKind.Book
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteRemovedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="favoriteId">Optional. The unique identifier of the removed favorite.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that owned the favorite.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the media item that was unfavorited.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of the media item that was unfavorited. Defaults to a random supported kind.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="FavoriteRemovedDomainEvent"/>.</returns>
|
||||
public FavoriteRemovedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
FavoriteId? favoriteId = null,
|
||||
UserId? userId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new FavoriteRemovedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
favoriteId ?? _favoriteIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="FavoriteRemovedDomainEvent"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteRemovedDomainEvent"/> instances.</returns>
|
||||
public List<FavoriteRemovedDomainEvent> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Favorite"/> domain aggregate.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly FavoriteIdFixture _favoriteIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly FavoriteMediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
FavoriteMediaKind.MusicArtist,
|
||||
FavoriteMediaKind.MusicAlbum,
|
||||
FavoriteMediaKind.MusicTrack,
|
||||
FavoriteMediaKind.Book
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Favorite"/> domain aggregate, with pre-existing data.
|
||||
/// </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="mediaItemId">Optional. The Id of the favorited media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of the favorited media item. Defaults to a random supported kind.</param>
|
||||
/// <param name="createdOnUtc">Optional. The date and time when the favorite was created. Defaults to a few days in the past.</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, or to no value when <paramref name="includeUpdatedOnUtc"/> is <see langword="false"/>.</param>
|
||||
/// <param name="includeUpdatedOnUtc">Whether to generate an update date and time when <paramref name="updatedOnUtc"/> is not supplied.</param>
|
||||
/// <returns>The created <see cref="Favorite"/>.</returns>
|
||||
/// <remarks>
|
||||
/// The favorite is built through the rehydrating <see cref="Favorite.Create(FavoriteId, UserId, MediaItemId, FavoriteMediaKind, DateTime, Optional{DateTime})"/>
|
||||
/// overload, so it carries no domain events, is never marked as removed, and keeps whatever media kind it is given, including a planned one.
|
||||
/// </remarks>
|
||||
public Favorite Create(
|
||||
FavoriteId? id = null,
|
||||
UserId? userId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
FavoriteMediaKind? mediaKind = null,
|
||||
DateTime? createdOnUtc = null,
|
||||
Optional<DateTime>? updatedOnUtc = null,
|
||||
bool includeUpdatedOnUtc = true)
|
||||
{
|
||||
DateTime resolvedCreatedOnUtc = createdOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).AddMinutes(-_faker.Random.Int(0, 59));
|
||||
return Favorite.Create(
|
||||
id ?? _favoriteIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
resolvedCreatedOnUtc,
|
||||
ResolveUpdatedOnUtc(updatedOnUtc, includeUpdatedOnUtc, resolvedCreatedOnUtc)).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="Favorite"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="Favorite"/> instances.</returns>
|
||||
public List<Favorite> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the update date and time of the favorite, keeping it at or after the creation date and inside the date range.
|
||||
/// </summary>
|
||||
/// <param name="updatedOnUtc">The explicitly supplied update date and time, if any.</param>
|
||||
/// <param name="includeUpdatedOnUtc">Whether to generate an update date and time when none is supplied.</param>
|
||||
/// <param name="createdOnUtc">The creation date and time of the favorite.</param>
|
||||
/// <returns>The resolved update date and time, or no value when the favorite was never updated.</returns>
|
||||
private Optional<DateTime> ResolveUpdatedOnUtc(Optional<DateTime>? updatedOnUtc, bool includeUpdatedOnUtc, DateTime createdOnUtc)
|
||||
{
|
||||
if (updatedOnUtc.HasValue)
|
||||
return updatedOnUtc.Value;
|
||||
if (!includeUpdatedOnUtc)
|
||||
return Optional<DateTime>.None();
|
||||
TimeSpan offsetFromCreation = TimeSpan.FromMinutes(_faker.Random.Int(0, 1440));
|
||||
return Optional<DateTime>.Some(DateTime.MaxValue - createdOnUtc < offsetFromCreation
|
||||
? DateTime.MaxValue
|
||||
: createdOnUtc.Add(offsetFromCreation));
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FavoriteBoundedContext.FavoriteAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FavoriteId"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FavoriteIdFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FavoriteId"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The raw value of the favorite Id.</param>
|
||||
/// <returns>The created <see cref="FavoriteId"/>.</returns>
|
||||
public FavoriteId Create(
|
||||
Guid? value = null)
|
||||
{
|
||||
return FavoriteId.Create(value ?? Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FavoriteId"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="FavoriteId"/> instances.</returns>
|
||||
public List<FavoriteId> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user