#region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Application.Common.DTO.MediaConsumption; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; #endregion namespace Lumina.Application.Fixtures.Common.DTO.MediaConsumption; /// /// Fixture class for the record. /// [ExcludeFromCodeCoverage] public class MediaKindConsumptionStatisticsDtoFixture { private const int MAXIMUM_DURATION_MILLISECONDS = 36_000_000; private readonly Faker _faker = new(); private readonly MediaKind[] _supportedMediaKinds = [ MediaKind.MusicTrack, MediaKind.PodcastEpisode, MediaKind.Audiobook, MediaKind.Movie, MediaKind.TvEpisode, MediaKind.Book, MediaKind.Photo, MediaKind.Video ]; /// /// Creates a random valid . /// /// Optional. The kind of media the statistics belong to. Defaults to a random supported kind. /// Optional. The total consumed duration of the media kind, in milliseconds. Defaults to a bounded random duration. /// Optional. The number of sessions that count towards statistics. /// Optional. The number of sessions that completed. /// Optional. The number of sessions that stopped before they completed. /// Optional. The completion rate. Defaults to a bounded random fraction between zero and one. /// The created . public MediaKindConsumptionStatisticsDto Create( MediaKind? mediaKind = null, long? totalConsumedDurationMilliseconds = null, int? countedSessionCount = null, int? completedSessionCount = null, int? stoppedSessionCount = null, double? completionRate = null) { return new MediaKindConsumptionStatisticsDto( mediaKind ?? _faker.Random.ArrayElement(_supportedMediaKinds), totalConsumedDurationMilliseconds ?? _faker.Random.Long(0, MAXIMUM_DURATION_MILLISECONDS), countedSessionCount ?? _faker.Random.Int(0, 100), completedSessionCount ?? _faker.Random.Int(0, 100), stoppedSessionCount ?? _faker.Random.Int(0, 100), completionRate ?? _faker.Random.Double(0, 1)); } /// /// Creates a list of instances with randomized test data. /// /// Number of instances to create. /// List of configured instances. public List CreateMany(int count = 3) { return [.. Enumerable.Range(0, count).Select(_ => Create())]; } }