mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Implements tests for commit fa8513cc71
This commit is contained in:
1 parent
5c436fc13d
commit
f7c2186660
15 files changed
+2970
No files matched your search
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaPosition"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaPositionFixture
|
||||
{
|
||||
private const int MAXIMUM_OFFSET_MILLISECONDS = 7_200_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaPosition"/>.
|
||||
/// </summary>
|
||||
/// <param name="kind">Optional. The kind of representation that the position uses. Defaults to a random valid kind.</param>
|
||||
/// <param name="timeOffset">Optional. The time offset of the position. Only used when <paramref name="kind"/> is <see cref="MediaPositionKind.TimeOffset"/>.</param>
|
||||
/// <param name="location">Optional. The location of the position. Only used when <paramref name="kind"/> is <see cref="MediaPositionKind.Location"/>.</param>
|
||||
/// <returns>The created <see cref="MediaPosition"/>.</returns>
|
||||
/// <remarks>
|
||||
/// The kind selects which representation is populated, so exactly one of <paramref name="timeOffset"/> and <paramref name="location"/> is used. A
|
||||
/// position always carries the representation of its own kind and can never carry both or neither, so no include flag is offered for them.
|
||||
/// There is no flag for an explicit empty <paramref name="location"/> either, because an empty string is already an explicit value.
|
||||
/// </remarks>
|
||||
public MediaPosition Create(
|
||||
MediaPositionKind? kind = null,
|
||||
TimeSpan? timeOffset = null,
|
||||
string? location = null)
|
||||
{
|
||||
MediaPositionKind resolvedKind = kind ?? _faker.Random.ArrayElement([MediaPositionKind.TimeOffset, MediaPositionKind.Location]);
|
||||
if (resolvedKind == MediaPositionKind.Location)
|
||||
return MediaPosition.CreateLocation(location ?? _faker.Lorem.Word());
|
||||
return MediaPosition.CreateTimeOffset(timeOffset ?? TimeSpan.FromMilliseconds(_faker.Random.Int(0, MAXIMUM_OFFSET_MILLISECONDS)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="MediaPosition"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaPosition"/> instances.</returns>
|
||||
public List<MediaPosition> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionCompletedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionCompletedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionCompletedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="mediaConsumptionRecordId">Optional. The unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="libraryId">Optional. The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that was consumed. Defaults to a random supported kind.</param>
|
||||
/// <param name="lastPosition">Optional. The last known position for the media item. Defaults to no position, unless <paramref name="includeLastPosition"/> is set.</param>
|
||||
/// <param name="includeLastPosition">Whether to generate a last position when none is supplied. Must be <see langword="false"/> for a photo, which has no position kind and accepts no position at all.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The final progress fraction reported for the media item. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="consumedDuration">Optional. The active duration consumed by the session. Defaults to a bounded random duration.</param>
|
||||
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read in the session. Defaults to a bounded random count for a page based kind, and to zero for every other kind.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionCompletedDomainEvent"/>.</returns>
|
||||
public MediaConsumptionCompletedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
MediaConsumptionRecordId? mediaConsumptionRecordId = null,
|
||||
UserId? userId = null,
|
||||
LibraryId? libraryId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
Optional<MediaPosition>? lastPosition = null,
|
||||
bool includeLastPosition = false,
|
||||
double? lastProgressFraction = null,
|
||||
TimeSpan? consumedDuration = null,
|
||||
int? consecutivePagesRead = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(resolvedMediaKind);
|
||||
bool isPageBased = ruleResult.HasValue && ruleResult.Value is PageThresholdConsumptionRule;
|
||||
|
||||
return new MediaConsumptionCompletedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
mediaConsumptionRecordId ?? _mediaConsumptionRecordIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
libraryId ?? _libraryIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
resolvedMediaKind,
|
||||
lastPosition ?? ResolveLastPosition(includeLastPosition, ruleResult),
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
consumedDuration ?? TimeSpan.FromSeconds(_faker.Random.Int(0, 36000)),
|
||||
consecutivePagesRead ?? (isPageBased ? _faker.Random.Int(0, 100) : 0),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the last position of the domain event, keeping it consistent with the position kind of the media kind rule.
|
||||
/// </summary>
|
||||
/// <param name="includeLastPosition">Whether to generate a position.</param>
|
||||
/// <param name="ruleResult">The consumption rule of the media kind of the domain event, if the kind has one.</param>
|
||||
/// <returns>The resolved last position, or no value when the domain event carries no position.</returns>
|
||||
private Optional<MediaPosition> ResolveLastPosition(bool includeLastPosition, Optional<MediaConsumptionRule> ruleResult)
|
||||
{
|
||||
if (!includeLastPosition)
|
||||
return Optional<MediaPosition>.None();
|
||||
if (!ruleResult.HasValue || !ruleResult.Value.PositionKind.HasValue)
|
||||
return Optional<MediaPosition>.None();
|
||||
return Optional<MediaPosition>.Some(_mediaPositionFixture.Create(kind: ruleResult.Value.PositionKind.Value));
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionProgressedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionProgressedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionProgressedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="mediaConsumptionRecordId">Optional. The unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="libraryId">Optional. The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that is being consumed. Defaults to a random supported kind.</param>
|
||||
/// <param name="lastPosition">Optional. The last known position for the media item. Defaults to no position, unless <paramref name="includeLastPosition"/> is set.</param>
|
||||
/// <param name="includeLastPosition">Whether to generate a last position when none is supplied. Must be <see langword="false"/> for a photo, which has no position kind and accepts no position at all.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The last progress fraction reported by the client. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="consumedDuration">Optional. The active duration consumed so far. Defaults to a bounded random duration.</param>
|
||||
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read so far. Defaults to a bounded random count for a page based kind, and to zero for every other kind.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionProgressedDomainEvent"/>.</returns>
|
||||
public MediaConsumptionProgressedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
MediaConsumptionRecordId? mediaConsumptionRecordId = null,
|
||||
UserId? userId = null,
|
||||
LibraryId? libraryId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
Optional<MediaPosition>? lastPosition = null,
|
||||
bool includeLastPosition = false,
|
||||
double? lastProgressFraction = null,
|
||||
TimeSpan? consumedDuration = null,
|
||||
int? consecutivePagesRead = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(resolvedMediaKind);
|
||||
bool isPageBased = ruleResult.HasValue && ruleResult.Value is PageThresholdConsumptionRule;
|
||||
|
||||
return new MediaConsumptionProgressedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
mediaConsumptionRecordId ?? _mediaConsumptionRecordIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
libraryId ?? _libraryIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
resolvedMediaKind,
|
||||
lastPosition ?? ResolveLastPosition(includeLastPosition, ruleResult),
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
consumedDuration ?? TimeSpan.FromSeconds(_faker.Random.Int(0, 36000)),
|
||||
consecutivePagesRead ?? (isPageBased ? _faker.Random.Int(0, 100) : 0),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the last position of the domain event, keeping it consistent with the position kind of the media kind rule.
|
||||
/// </summary>
|
||||
/// <param name="includeLastPosition">Whether to generate a position.</param>
|
||||
/// <param name="ruleResult">The consumption rule of the media kind of the domain event, if the kind has one.</param>
|
||||
/// <returns>The resolved last position, or no value when the domain event carries no position.</returns>
|
||||
private Optional<MediaPosition> ResolveLastPosition(bool includeLastPosition, Optional<MediaConsumptionRule> ruleResult)
|
||||
{
|
||||
if (!includeLastPosition)
|
||||
return Optional<MediaPosition>.None();
|
||||
if (!ruleResult.HasValue || !ruleResult.Value.PositionKind.HasValue)
|
||||
return Optional<MediaPosition>.None();
|
||||
return Optional<MediaPosition>.Some(_mediaPositionFixture.Create(kind: ruleResult.Value.PositionKind.Value));
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionStartedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionStartedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionStartedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="mediaConsumptionRecordId">Optional. The unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that started the session.</param>
|
||||
/// <param name="libraryId">Optional. The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that is being consumed. 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="MediaConsumptionStartedDomainEvent"/>.</returns>
|
||||
public MediaConsumptionStartedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
MediaConsumptionRecordId? mediaConsumptionRecordId = null,
|
||||
UserId? userId = null,
|
||||
LibraryId? libraryId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new MediaConsumptionStartedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
mediaConsumptionRecordId ?? _mediaConsumptionRecordIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
libraryId ?? _libraryIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionStoppedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionStoppedDomainEventFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionStoppedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="mediaConsumptionRecordId">Optional. The unique identifier of the consumption record.</param>
|
||||
/// <param name="userId">Optional. The unique identifier of the user that owns the consumption record.</param>
|
||||
/// <param name="libraryId">Optional. The unique identifier of the media library that contains the consumed item.</param>
|
||||
/// <param name="mediaItemId">Optional. The unique identifier of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that was consumed. Defaults to a random supported kind.</param>
|
||||
/// <param name="lastPosition">Optional. The last known position for the media item. Defaults to no position, unless <paramref name="includeLastPosition"/> is set.</param>
|
||||
/// <param name="includeLastPosition">Whether to generate a last position when none is supplied. Must be <see langword="false"/> for a photo, which has no position kind and accepts no position at all.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The final progress fraction reported for the media item. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="consumedDuration">Optional. The active duration consumed by the session. Defaults to a bounded random duration.</param>
|
||||
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read in the session. Defaults to a bounded random count for a page based kind, and to zero for every other kind.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionStoppedDomainEvent"/>.</returns>
|
||||
public MediaConsumptionStoppedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
MediaConsumptionRecordId? mediaConsumptionRecordId = null,
|
||||
UserId? userId = null,
|
||||
LibraryId? libraryId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
Optional<MediaPosition>? lastPosition = null,
|
||||
bool includeLastPosition = false,
|
||||
double? lastProgressFraction = null,
|
||||
TimeSpan? consumedDuration = null,
|
||||
int? consecutivePagesRead = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(resolvedMediaKind);
|
||||
bool isPageBased = ruleResult.HasValue && ruleResult.Value is PageThresholdConsumptionRule;
|
||||
|
||||
return new MediaConsumptionStoppedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
mediaConsumptionRecordId ?? _mediaConsumptionRecordIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
libraryId ?? _libraryIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
resolvedMediaKind,
|
||||
lastPosition ?? ResolveLastPosition(includeLastPosition, ruleResult),
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
consumedDuration ?? TimeSpan.FromSeconds(_faker.Random.Int(0, 36000)),
|
||||
consecutivePagesRead ?? (isPageBased ? _faker.Random.Int(0, 100) : 0),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the last position of the domain event, keeping it consistent with the position kind of the media kind rule.
|
||||
/// </summary>
|
||||
/// <param name="includeLastPosition">Whether to generate a position.</param>
|
||||
/// <param name="ruleResult">The consumption rule of the media kind of the domain event, if the kind has one.</param>
|
||||
/// <returns>The resolved last position, or no value when the domain event carries no position.</returns>
|
||||
private Optional<MediaPosition> ResolveLastPosition(bool includeLastPosition, Optional<MediaConsumptionRule> ruleResult)
|
||||
{
|
||||
if (!includeLastPosition)
|
||||
return Optional<MediaPosition>.None();
|
||||
if (!ruleResult.HasValue || !ruleResult.Value.PositionKind.HasValue)
|
||||
return Optional<MediaPosition>.None();
|
||||
return Optional<MediaPosition>.Some(_mediaPositionFixture.Create(kind: ruleResult.Value.PositionKind.Value));
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionRecord"/> domain aggregate.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionRecordFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaKind[] _supportedMediaKinds =
|
||||
[
|
||||
MediaKind.MusicTrack,
|
||||
MediaKind.PodcastEpisode,
|
||||
MediaKind.Audiobook,
|
||||
MediaKind.Movie,
|
||||
MediaKind.TvEpisode,
|
||||
MediaKind.Book,
|
||||
MediaKind.Photo,
|
||||
MediaKind.Video
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionRecord"/> domain aggregate, with pre-existing data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the consumption record.</param>
|
||||
/// <param name="userId">Optional. The Id of the user that owns the consumption record.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="mediaItemId">Optional. The Id of the consumed media item.</param>
|
||||
/// <param name="mediaKind">Optional. The kind of media that is consumed. Defaults to a random supported kind.</param>
|
||||
/// <param name="status">Optional. The status of the consumption session. Defaults to a random valid status.</param>
|
||||
/// <param name="startedOnUtc">Optional. The date and time when the consumption session started. Defaults to a few days in the past.</param>
|
||||
/// <param name="lastActivityOnUtc">Optional. The date and time of the last activity of the consumption session. Defaults to a moment at or after the start.</param>
|
||||
/// <param name="endedOnUtc">Optional. The date and time when the consumption session ended. Defaults to no value for an in-progress session, and to a moment at or after the last activity for a terminal session.</param>
|
||||
/// <param name="consumedDuration">Optional. The active duration consumed by the session. Defaults to a bounded random duration.</param>
|
||||
/// <param name="lastPosition">Optional. The last position of the session. When omitted, a position matching the position kind of the media kind rule is generated.</param>
|
||||
/// <param name="includeLastPosition">Whether to generate a last position when <paramref name="lastPosition"/> is not supplied. Must be <see langword="false"/> for a photo, which has no position kind and accepts no position at all.</param>
|
||||
/// <param name="lastProgressFraction">Optional. The last progress fraction of the session. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="consecutivePagesRead">Optional. The number of consecutive pages read. Defaults to a bounded random count for a page based kind, and to zero for every other kind.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionRecord"/>.</returns>
|
||||
/// <remarks>
|
||||
/// The record is built through <see cref="MediaConsumptionRecord.Reconstitute"/>, so every default produced here is internally consistent: the
|
||||
/// start is in the past, the last activity never precedes it, an end time exists exactly when the status is terminal and never precedes the last
|
||||
/// activity, consecutive pages are only counted for a book, and a generated position always uses the position kind of its media kind.
|
||||
/// </remarks>
|
||||
public MediaConsumptionRecord Create(
|
||||
MediaConsumptionRecordId? id = null,
|
||||
UserId? userId = null,
|
||||
LibraryId? libraryId = null,
|
||||
MediaItemId? mediaItemId = null,
|
||||
MediaKind? mediaKind = null,
|
||||
ConsumptionStatus? status = null,
|
||||
DateTime? startedOnUtc = null,
|
||||
DateTime? lastActivityOnUtc = null,
|
||||
Optional<DateTime>? endedOnUtc = null,
|
||||
TimeSpan? consumedDuration = null,
|
||||
Optional<MediaPosition>? lastPosition = null,
|
||||
bool includeLastPosition = true,
|
||||
double? lastProgressFraction = null,
|
||||
int? consecutivePagesRead = null)
|
||||
{
|
||||
MediaKind resolvedMediaKind = mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds);
|
||||
ConsumptionStatus resolvedStatus = status ?? _faker.Random.ArrayElement([ConsumptionStatus.InProgress, ConsumptionStatus.Completed, ConsumptionStatus.Stopped]);
|
||||
DateTime resolvedStartedOnUtc = startedOnUtc ?? DateTime.UtcNow.AddDays(-_faker.Random.Int(1, 30)).AddMinutes(-_faker.Random.Int(0, 59));
|
||||
DateTime resolvedLastActivityOnUtc = lastActivityOnUtc ?? resolvedStartedOnUtc.AddMinutes(_faker.Random.Int(0, 120));
|
||||
Optional<DateTime> resolvedEndedOnUtc = endedOnUtc ?? (resolvedStatus == ConsumptionStatus.InProgress
|
||||
? Optional<DateTime>.None()
|
||||
: Optional<DateTime>.Some(resolvedLastActivityOnUtc == DateTime.MaxValue
|
||||
? DateTime.MaxValue
|
||||
: resolvedLastActivityOnUtc.AddMinutes(_faker.Random.Int(0, 60))));
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(resolvedMediaKind);
|
||||
bool isPageBased = ruleResult.HasValue && ruleResult.Value is PageThresholdConsumptionRule;
|
||||
|
||||
Result<MediaConsumptionRecord> result = MediaConsumptionRecord.Reconstitute(
|
||||
id ?? _mediaConsumptionRecordIdFixture.Create(),
|
||||
userId ?? _userIdFixture.Create(),
|
||||
libraryId ?? _libraryIdFixture.Create(),
|
||||
mediaItemId ?? _mediaItemIdFixture.Create(),
|
||||
resolvedMediaKind,
|
||||
resolvedStatus,
|
||||
resolvedStartedOnUtc,
|
||||
resolvedLastActivityOnUtc,
|
||||
resolvedEndedOnUtc,
|
||||
consumedDuration ?? TimeSpan.FromSeconds(_faker.Random.Int(0, 36000)),
|
||||
ResolveLastPosition(lastPosition, includeLastPosition, ruleResult),
|
||||
lastProgressFraction ?? _faker.Random.Double(0, 1),
|
||||
consecutivePagesRead ?? (isPageBased ? _faker.Random.Int(0, 100) : 0));
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="MediaConsumptionRecord"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaConsumptionRecord"/> instances.</returns>
|
||||
public List<MediaConsumptionRecord> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the last position of the record, keeping it consistent with the position kind of its media kind rule.
|
||||
/// </summary>
|
||||
/// <param name="lastPosition">The explicitly supplied last position, if any.</param>
|
||||
/// <param name="includeLastPosition">Whether to generate a position when none is supplied.</param>
|
||||
/// <param name="ruleResult">The consumption rule of the media kind of the record, if the kind has one.</param>
|
||||
/// <returns>The resolved last position, or no value when the record carries no position.</returns>
|
||||
private Optional<MediaPosition> ResolveLastPosition(Optional<MediaPosition>? lastPosition, bool includeLastPosition, Optional<MediaConsumptionRule> ruleResult)
|
||||
{
|
||||
if (!includeLastPosition)
|
||||
return Optional<MediaPosition>.None();
|
||||
if (lastPosition.HasValue)
|
||||
return lastPosition.Value;
|
||||
if (!ruleResult.HasValue || !ruleResult.Value.PositionKind.HasValue)
|
||||
return Optional<MediaPosition>.None();
|
||||
return Optional<MediaPosition>.Some(_mediaPositionFixture.Create(kind: ruleResult.Value.PositionKind.Value));
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaConsumptionRecordId"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionRecordIdFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaConsumptionRecordId"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The raw value of the consumption record Id.</param>
|
||||
/// <returns>The created <see cref="MediaConsumptionRecordId"/>.</returns>
|
||||
public MediaConsumptionRecordId Create(
|
||||
Guid? value = null)
|
||||
{
|
||||
return MediaConsumptionRecordId.Create(value ?? Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="MediaConsumptionRecordId"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaConsumptionRecordId"/> instances.</returns>
|
||||
public List<MediaConsumptionRecordId> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
@@ -224,6 +224,36 @@ public class ErrorsTests
|
||||
AssertError(DomainErrors.MediaContributors.MediaContributorRoleNameCannotBeEmpty, ErrorType.Validation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MediaConsumption_WhenAccessed_ShouldExposeErrorsWithExpectedTypes()
|
||||
{
|
||||
// Assert
|
||||
// The count assertion fails when an error is added or removed, reminding to update the assertions below.
|
||||
Assert.Equal(22, typeof(DomainErrors.MediaConsumption).GetProperties().Length);
|
||||
AssertError(DomainErrors.MediaConsumption.UnsupportedMediaKind, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.MediaKindCannotStartCompleted, ErrorType.Forbidden);
|
||||
AssertError(DomainErrors.MediaConsumption.MediaKindCannotResume, ErrorType.Forbidden);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumptionRecordNotFound, ErrorType.NotFound);
|
||||
AssertError(DomainErrors.MediaConsumption.MediaResumePointNotFound, ErrorType.NotFound);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumptionRecordIdCannotBeEmpty, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.MediaItemIdCannotBeEmpty, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.TargetUserIdIsInvalid, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumptionDateRangeIsInvalid, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.InvalidMediaPosition, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.InvalidProgressFraction, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumedDurationMustBeNonNegative, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumedDurationIsOutOfRange, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumedDurationCannotDecrease, ErrorType.Forbidden);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsecutivePagesReadMustBeNonNegative, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsecutivePagesReadIsOnlySupportedForPageBasedMedia, ErrorType.Forbidden);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumptionIsNotInProgress, ErrorType.Conflict);
|
||||
AssertError(DomainErrors.MediaConsumption.ConsumptionIsAlreadyTerminal, ErrorType.Conflict);
|
||||
AssertError(DomainErrors.MediaConsumption.InProgressConsumptionCannotHaveEndTime, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.EndedConsumptionMustHaveEndTime, ErrorType.Validation);
|
||||
AssertError(DomainErrors.MediaConsumption.LastActivityCannotPrecedeStart, ErrorType.Forbidden);
|
||||
AssertError(DomainErrors.MediaConsumption.EndedConsumptionCannotPrecedeLastActivity, ErrorType.Forbidden);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FileSystemManagement_WhenAccessed_ShouldExposeErrorsWithExpectedTypes()
|
||||
{
|
||||
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaPosition"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaPositionTests
|
||||
{
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateTimeOffset_WhenCalled_ShouldSetTimeOffsetKindAndTheOffset()
|
||||
{
|
||||
// Arrange
|
||||
TimeSpan timeOffset = TimeSpan.FromMinutes(42);
|
||||
|
||||
// Act
|
||||
MediaPosition position = MediaPosition.CreateTimeOffset(timeOffset);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(MediaPositionKind.TimeOffset, position.Kind);
|
||||
Assert.True(position.TimeOffset.HasValue);
|
||||
Assert.Equal(timeOffset, position.TimeOffset.Value);
|
||||
Assert.False(position.Location.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateLocation_WhenCalled_ShouldSetLocationKindAndTheLocation()
|
||||
{
|
||||
// Arrange
|
||||
string location = "chapter-7/page-12";
|
||||
|
||||
// Act
|
||||
MediaPosition position = MediaPosition.CreateLocation(location);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(MediaPositionKind.Location, position.Kind);
|
||||
Assert.True(position.Location.HasValue);
|
||||
Assert.Equal(location, position.Location.Value);
|
||||
Assert.False(position.TimeOffset.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateTimeOffset_WhenOffsetIsNegative_ShouldStoreTheOffsetAsGiven()
|
||||
{
|
||||
// Arrange
|
||||
TimeSpan negativeTimeOffset = TimeSpan.FromMinutes(-1);
|
||||
|
||||
// Act
|
||||
MediaPosition position = MediaPosition.CreateTimeOffset(negativeTimeOffset);
|
||||
|
||||
// Assert
|
||||
// the value object does not validate the sign of the offset, the reported value is stored as given
|
||||
Assert.Equal(TimeSpan.FromMinutes(-1), position.TimeOffset.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateLocation_WhenLocationIsEmpty_ShouldStoreTheEmptyLocation()
|
||||
{
|
||||
// Act
|
||||
MediaPosition position = MediaPosition.CreateLocation(string.Empty);
|
||||
|
||||
// Assert
|
||||
// the value object does not validate the content of the location, the reported value is stored as given
|
||||
Assert.True(position.Location.HasValue);
|
||||
Assert.Equal(string.Empty, position.Location.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WhenKindAndValueAreTheSame_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition firstPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset, timeOffset: TimeSpan.FromMinutes(10));
|
||||
MediaPosition secondPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset, timeOffset: TimeSpan.FromMinutes(10));
|
||||
|
||||
// Act
|
||||
bool result = firstPosition.Equals(secondPosition);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WhenTimeOffsetDiffers_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition firstPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset, timeOffset: TimeSpan.FromMinutes(10));
|
||||
MediaPosition secondPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset, timeOffset: TimeSpan.FromMinutes(11));
|
||||
|
||||
// Act
|
||||
bool result = firstPosition.Equals(secondPosition);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WhenLocationDiffers_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition firstPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location, location: "chapter-1");
|
||||
MediaPosition secondPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location, location: "chapter-2");
|
||||
|
||||
// Act
|
||||
bool result = firstPosition.Equals(secondPosition);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WhenKindDiffers_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition firstPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset, timeOffset: TimeSpan.FromMinutes(10));
|
||||
MediaPosition secondPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location, location: "chapter-1");
|
||||
|
||||
// Act
|
||||
bool result = firstPosition.Equals(secondPosition);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCode_WhenKindAndValueAreTheSame_ShouldReturnSameHashCode()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition firstPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location, location: "chapter-3");
|
||||
MediaPosition secondPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location, location: "chapter-3");
|
||||
|
||||
// Act
|
||||
int firstHashCode = firstPosition.GetHashCode();
|
||||
int secondHashCode = secondPosition.GetHashCode();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstHashCode, secondHashCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEqualityComponents_WhenCalled_ShouldYieldKindThenTimeOffsetThenLocation()
|
||||
{
|
||||
// Arrange
|
||||
MediaPosition position = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset);
|
||||
|
||||
// Act
|
||||
object?[] components = [.. position.GetEqualityComponents()];
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, components.Length);
|
||||
Assert.Equal(MediaPositionKind.TimeOffset, Assert.IsType<MediaPositionKind>(components[0]));
|
||||
Assert.Equal(position.TimeOffset, Assert.IsType<Optional<TimeSpan>>(components[1]));
|
||||
Assert.Equal(position.Location, Assert.IsType<Optional<string>>(components[2]));
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaConsumptionCompletedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionCompletedDomainEventTests
|
||||
{
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaConsumptionCompletedDomainEventFixture _mediaConsumptionCompletedDomainEventFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaItemId mediaItemId = _mediaItemIdFixture.Create();
|
||||
MediaPosition lastPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.Location);
|
||||
double lastProgressFraction = 1.0;
|
||||
TimeSpan consumedDuration = TimeSpan.FromHours(2);
|
||||
int consecutivePagesRead = 12;
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
MediaConsumptionCompletedDomainEvent domainEvent = _mediaConsumptionCompletedDomainEventFixture.Create(
|
||||
id,
|
||||
mediaConsumptionRecordId,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
MediaKind.Book,
|
||||
lastPosition: Optional<MediaPosition>.Some(lastPosition),
|
||||
lastProgressFraction: lastProgressFraction,
|
||||
consumedDuration: consumedDuration,
|
||||
consecutivePagesRead: consecutivePagesRead,
|
||||
occurredOnUtc: occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(mediaConsumptionRecordId, domainEvent.MediaConsumptionRecordId);
|
||||
Assert.Equal(userId, domainEvent.UserId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(mediaItemId, domainEvent.MediaItemId);
|
||||
Assert.Equal(MediaKind.Book, domainEvent.MediaKind);
|
||||
Assert.Equal(Optional<MediaPosition>.Some(lastPosition), domainEvent.LastPosition);
|
||||
Assert.Equal(lastProgressFraction, domainEvent.LastProgressFraction);
|
||||
Assert.Equal(consumedDuration, domainEvent.ConsumedDuration);
|
||||
Assert.Equal(consecutivePagesRead, domainEvent.ConsecutivePagesRead);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenLastPositionIsAbsent_ShouldSetNoLastPosition()
|
||||
{
|
||||
// Arrange
|
||||
MediaConsumptionCompletedDomainEvent domainEvent = _mediaConsumptionCompletedDomainEventFixture.Create(mediaKind: MediaKind.Photo);
|
||||
|
||||
// Act
|
||||
Optional<MediaPosition> lastPosition = domainEvent.LastPosition;
|
||||
|
||||
// Assert
|
||||
Assert.False(lastPosition.HasValue);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaConsumptionProgressedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionProgressedDomainEventTests
|
||||
{
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaConsumptionProgressedDomainEventFixture _mediaConsumptionProgressedDomainEventFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaItemId mediaItemId = _mediaItemIdFixture.Create();
|
||||
MediaPosition lastPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset);
|
||||
double lastProgressFraction = 0.4;
|
||||
TimeSpan consumedDuration = TimeSpan.FromMinutes(25);
|
||||
int consecutivePagesRead = 0;
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
MediaConsumptionProgressedDomainEvent domainEvent = _mediaConsumptionProgressedDomainEventFixture.Create(
|
||||
id,
|
||||
mediaConsumptionRecordId,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
MediaKind.Movie,
|
||||
lastPosition: Optional<MediaPosition>.Some(lastPosition),
|
||||
lastProgressFraction: lastProgressFraction,
|
||||
consumedDuration: consumedDuration,
|
||||
consecutivePagesRead: consecutivePagesRead,
|
||||
occurredOnUtc: occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(mediaConsumptionRecordId, domainEvent.MediaConsumptionRecordId);
|
||||
Assert.Equal(userId, domainEvent.UserId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(mediaItemId, domainEvent.MediaItemId);
|
||||
Assert.Equal(MediaKind.Movie, domainEvent.MediaKind);
|
||||
Assert.Equal(Optional<MediaPosition>.Some(lastPosition), domainEvent.LastPosition);
|
||||
Assert.Equal(lastProgressFraction, domainEvent.LastProgressFraction);
|
||||
Assert.Equal(consumedDuration, domainEvent.ConsumedDuration);
|
||||
Assert.Equal(consecutivePagesRead, domainEvent.ConsecutivePagesRead);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenLastPositionIsAbsent_ShouldSetNoLastPosition()
|
||||
{
|
||||
// Arrange
|
||||
MediaConsumptionProgressedDomainEvent domainEvent = _mediaConsumptionProgressedDomainEventFixture.Create(mediaKind: MediaKind.Movie);
|
||||
|
||||
// Act
|
||||
Optional<MediaPosition> lastPosition = domainEvent.LastPosition;
|
||||
|
||||
// Assert
|
||||
Assert.False(lastPosition.HasValue);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaConsumptionStartedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionStartedDomainEventTests
|
||||
{
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaConsumptionStartedDomainEventFixture _mediaConsumptionStartedDomainEventFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaItemId mediaItemId = _mediaItemIdFixture.Create();
|
||||
MediaKind mediaKind = MediaKind.Movie;
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
MediaConsumptionStartedDomainEvent domainEvent = _mediaConsumptionStartedDomainEventFixture.Create(
|
||||
id,
|
||||
mediaConsumptionRecordId,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
mediaKind,
|
||||
occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(mediaConsumptionRecordId, domainEvent.MediaConsumptionRecordId);
|
||||
Assert.Equal(userId, domainEvent.UserId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(mediaItemId, domainEvent.MediaItemId);
|
||||
Assert.Equal(mediaKind, domainEvent.MediaKind);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaConsumptionStoppedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionStoppedDomainEventTests
|
||||
{
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaItemIdFixture _mediaItemIdFixture = new();
|
||||
private readonly MediaPositionFixture _mediaPositionFixture = new();
|
||||
private readonly MediaConsumptionStoppedDomainEventFixture _mediaConsumptionStoppedDomainEventFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaItemId mediaItemId = _mediaItemIdFixture.Create();
|
||||
MediaPosition lastPosition = _mediaPositionFixture.Create(kind: MediaPositionKind.TimeOffset);
|
||||
double lastProgressFraction = 0.35;
|
||||
TimeSpan consumedDuration = TimeSpan.FromMinutes(18);
|
||||
int consecutivePagesRead = 0;
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
MediaConsumptionStoppedDomainEvent domainEvent = _mediaConsumptionStoppedDomainEventFixture.Create(
|
||||
id,
|
||||
mediaConsumptionRecordId,
|
||||
userId,
|
||||
libraryId,
|
||||
mediaItemId,
|
||||
MediaKind.TvEpisode,
|
||||
lastPosition: Optional<MediaPosition>.Some(lastPosition),
|
||||
lastProgressFraction: lastProgressFraction,
|
||||
consumedDuration: consumedDuration,
|
||||
consecutivePagesRead: consecutivePagesRead,
|
||||
occurredOnUtc: occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(mediaConsumptionRecordId, domainEvent.MediaConsumptionRecordId);
|
||||
Assert.Equal(userId, domainEvent.UserId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(mediaItemId, domainEvent.MediaItemId);
|
||||
Assert.Equal(MediaKind.TvEpisode, domainEvent.MediaKind);
|
||||
Assert.Equal(Optional<MediaPosition>.Some(lastPosition), domainEvent.LastPosition);
|
||||
Assert.Equal(lastProgressFraction, domainEvent.LastProgressFraction);
|
||||
Assert.Equal(consumedDuration, domainEvent.ConsumedDuration);
|
||||
Assert.Equal(consecutivePagesRead, domainEvent.ConsecutivePagesRead);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenLastPositionIsAbsent_ShouldSetNoLastPosition()
|
||||
{
|
||||
// Arrange
|
||||
MediaConsumptionStoppedDomainEvent domainEvent = _mediaConsumptionStoppedDomainEventFixture.Create(mediaKind: MediaKind.Movie);
|
||||
|
||||
// Act
|
||||
Optional<MediaPosition> lastPosition = domainEvent.LastPosition;
|
||||
|
||||
// Assert
|
||||
Assert.False(lastPosition.HasValue);
|
||||
}
|
||||
}
|
||||
+1676
File diff suppressed because it is too large.
Load diff
+126
@@ -0,0 +1,126 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaConsumptionRecordId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaConsumptionRecordIdTests
|
||||
{
|
||||
private readonly MediaConsumptionRecordIdFixture _mediaConsumptionRecordIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = MediaConsumptionRecordId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(mediaConsumptionRecordId);
|
||||
Assert.NotEqual(default, mediaConsumptionRecordId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalledTwice_ShouldReturnDistinctIds()
|
||||
{
|
||||
// Act
|
||||
MediaConsumptionRecordId firstId = MediaConsumptionRecordId.CreateUnique();
|
||||
MediaConsumptionRecordId secondId = MediaConsumptionRecordId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstId.Value, secondId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = MediaConsumptionRecordId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, mediaConsumptionRecordId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MediaConsumptionRecordId firstId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
MediaConsumptionRecordId secondId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaConsumptionRecordId firstId = _mediaConsumptionRecordIdFixture.Create();
|
||||
MediaConsumptionRecordId secondId = _mediaConsumptionRecordIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCode_WhenValuesAreEqual_ShouldReturnSameHashCode()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MediaConsumptionRecordId firstId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
MediaConsumptionRecordId secondId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
int firstHashCode = firstId.GetHashCode();
|
||||
int secondHashCode = secondId.GetHashCode();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstHashCode, secondHashCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetEqualityComponents_WhenCalled_ShouldYieldTheGuidValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
object?[] components = [.. mediaConsumptionRecordId.GetEqualityComponents()];
|
||||
|
||||
// Assert
|
||||
object? component = Assert.Single(components);
|
||||
Assert.Equal(value, Assert.IsType<Guid>(component));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenCalled_ShouldReturnTheGuidString()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MediaConsumptionRecordId mediaConsumptionRecordId = _mediaConsumptionRecordIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
string? result = mediaConsumptionRecordId.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value.ToString(), result);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user