mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Implements tests for commit f777af07cf
This commit is contained in:
1 parent
99fc721d8c
commit
54b468855a
54 files changed
+10681
-17
No files matched your search
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AllUsersConsumptionStatisticsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AllUsersConsumptionStatisticsResponseFixture
|
||||
{
|
||||
private readonly ConsumptionTotalsResponseFixture _consumptionTotalsResponseFixture = new();
|
||||
private readonly ConsumptionSummaryResponseFixture _consumptionSummaryResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AllUsersConsumptionStatisticsResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="total">Optional. The combined statistics of every user. Defaults to a random set of totals.</param>
|
||||
/// <param name="users">Optional. The statistics of each user. Defaults to a single random user summary.</param>
|
||||
/// <param name="includeUsers">Whether the user summaries should be included, or forced to an empty list.</param>
|
||||
/// <returns>The created <see cref="AllUsersConsumptionStatisticsResponse"/>.</returns>
|
||||
public AllUsersConsumptionStatisticsResponse Create(
|
||||
ConsumptionTotalsResponse? total = null,
|
||||
IReadOnlyList<ConsumptionSummaryResponse>? users = null,
|
||||
bool includeUsers = true)
|
||||
{
|
||||
IReadOnlyList<ConsumptionSummaryResponse> resolvedUsers = includeUsers
|
||||
? users ?? [_consumptionSummaryResponseFixture.Create()]
|
||||
: [];
|
||||
|
||||
return new AllUsersConsumptionStatisticsResponse(
|
||||
total ?? _consumptionTotalsResponseFixture.Create(),
|
||||
resolvedUsers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AllUsersConsumptionStatisticsResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="AllUsersConsumptionStatisticsResponse"/> instances.</returns>
|
||||
public List<AllUsersConsumptionStatisticsResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ConsumptionTotalsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ConsumptionTotalsResponseFixture
|
||||
{
|
||||
private const double MAXIMUM_DURATION_SECONDS = 36_000;
|
||||
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaKindConsumptionSummaryResponseFixture _mediaKindConsumptionSummaryResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ConsumptionTotalsResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="totalConsumedDurationInSeconds">Optional. The total consumed duration, in seconds. Defaults to a bounded random duration.</param>
|
||||
/// <param name="countedSessionCount">Optional. The number of sessions that count towards statistics.</param>
|
||||
/// <param name="completedSessionCount">Optional. The number of sessions that completed.</param>
|
||||
/// <param name="stoppedSessionCount">Optional. The number of sessions that stopped before they completed.</param>
|
||||
/// <param name="completionRate">Optional. The completion rate. Defaults to a bounded random fraction between zero and one.</param>
|
||||
/// <param name="mediaKindSummaries">Optional. The statistics broken down by media kind. Defaults to a single random summary.</param>
|
||||
/// <param name="includeMediaKindSummaries">Whether the media kind summaries should be included, or forced to an empty list.</param>
|
||||
/// <returns>The created <see cref="ConsumptionTotalsResponse"/>.</returns>
|
||||
public ConsumptionTotalsResponse Create(
|
||||
double? totalConsumedDurationInSeconds = null,
|
||||
int? countedSessionCount = null,
|
||||
int? completedSessionCount = null,
|
||||
int? stoppedSessionCount = null,
|
||||
double? completionRate = null,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryResponse>? mediaKindSummaries = null,
|
||||
bool includeMediaKindSummaries = true)
|
||||
{
|
||||
IReadOnlyList<MediaKindConsumptionSummaryResponse> resolvedMediaKindSummaries = includeMediaKindSummaries
|
||||
? mediaKindSummaries ?? [_mediaKindConsumptionSummaryResponseFixture.Create()]
|
||||
: [];
|
||||
|
||||
return new ConsumptionTotalsResponse(
|
||||
totalConsumedDurationInSeconds ?? _faker.Random.Double(0, MAXIMUM_DURATION_SECONDS),
|
||||
countedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
stoppedSessionCount ?? _faker.Random.Int(0, 100),
|
||||
completionRate ?? _faker.Random.Double(0, 1),
|
||||
resolvedMediaKindSummaries);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ConsumptionTotalsResponse"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ConsumptionTotalsResponse"/> instances.</returns>
|
||||
public List<ConsumptionTotalsResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user