mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Implements tests for commit bfa7b190b2
Covers the four consumption lifecycle Web proxy endpoints with unit, integration and security tests and their DTO and request fixtures. Changes the report progress Web route from POST to PUT, matching the upstream API, and updates the music player and the book reader to send that verb.
This commit is contained in:
1 parent
1afb078efc
commit
d3b4eec630
22 files changed
+3108
-5
No files matched your search
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.Requests.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CompleteConsumptionRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CompleteConsumptionRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CompleteConsumptionRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="position">Optional final position reported for the media item.</param>
|
||||
/// <param name="progressFraction">Optional fraction of the media item that the client reached, between 0 and 1.</param>
|
||||
/// <param name="consumedDurationInSeconds">Optional active duration consumed by the session, in seconds.</param>
|
||||
/// <param name="consecutivePagesRead">Optional number of consecutive pages read in the session.</param>
|
||||
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeConsecutivePagesRead">Whether the number of consecutive pages read should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>A configured <see cref="CompleteConsumptionRequest"/> instance.</returns>
|
||||
public CompleteConsumptionRequest Create(
|
||||
MediaPositionRequest? position = null,
|
||||
double? progressFraction = null,
|
||||
double? consumedDurationInSeconds = null,
|
||||
int? consecutivePagesRead = null,
|
||||
bool includePosition = true,
|
||||
bool includeConsecutivePagesRead = true)
|
||||
{
|
||||
return new CompleteConsumptionRequest(
|
||||
Position: includePosition ? (position ?? _mediaPositionRequestFixture.Create()) : null,
|
||||
ProgressFraction: progressFraction ?? _faker.Random.Double(0, 1),
|
||||
ConsumedDurationInSeconds: consumedDurationInSeconds ?? _faker.Random.Double(0, 100000),
|
||||
ConsecutivePagesRead: includeConsecutivePagesRead ? (consecutivePagesRead ?? _faker.Random.Int(0, 1000)) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="CompleteConsumptionRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="CompleteConsumptionRequest"/> instances.</returns>
|
||||
public List<CompleteConsumptionRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.MediaConsumption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaPositionRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaPositionRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaPositionRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="kind">Optional name of the kind of the position.</param>
|
||||
/// <param name="timeOffsetSeconds">Optional position within the media item, in seconds.</param>
|
||||
/// <param name="location">Optional opaque locator within the media item.</param>
|
||||
/// <param name="includeTimeOffsetSeconds">Whether the time offset should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeLocation">Whether the location should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>A configured <see cref="MediaPositionRequest"/> instance.</returns>
|
||||
public MediaPositionRequest Create(
|
||||
string? kind = null,
|
||||
double? timeOffsetSeconds = null,
|
||||
string? location = null,
|
||||
bool includeTimeOffsetSeconds = true,
|
||||
bool includeLocation = true)
|
||||
{
|
||||
MediaPositionKind resolvedRandomKind = _faker.PickRandom(MediaPositionKind.TimeOffset, MediaPositionKind.Location);
|
||||
bool isTimeOffset = kind is null
|
||||
? resolvedRandomKind == MediaPositionKind.TimeOffset
|
||||
: string.Equals(kind, nameof(MediaPositionKind.TimeOffset), StringComparison.OrdinalIgnoreCase);
|
||||
bool isLocation = kind is null
|
||||
? resolvedRandomKind == MediaPositionKind.Location
|
||||
: string.Equals(kind, nameof(MediaPositionKind.Location), StringComparison.OrdinalIgnoreCase);
|
||||
return new MediaPositionRequest(
|
||||
Kind: kind ?? resolvedRandomKind.ToString(),
|
||||
TimeOffsetSeconds: includeTimeOffsetSeconds ? (timeOffsetSeconds ?? (isTimeOffset ? _faker.Random.Double(0, 100000) : null)) : null,
|
||||
Location: includeLocation ? (location ?? (isLocation ? _faker.Random.AlphaNumeric(24) : null)) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="MediaPositionRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaPositionRequest"/> instances.</returns>
|
||||
public List<MediaPositionRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.Requests.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ReportConsumptionProgressRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReportConsumptionProgressRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ReportConsumptionProgressRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="position">Optional last position reported for the media item.</param>
|
||||
/// <param name="progressFraction">Optional fraction of the media item that the client reached, between 0 and 1.</param>
|
||||
/// <param name="consumedDurationInSeconds">Optional active duration consumed by the session, in seconds.</param>
|
||||
/// <param name="consecutivePagesRead">Optional number of consecutive pages read in the current session.</param>
|
||||
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>A configured <see cref="ReportConsumptionProgressRequest"/> instance.</returns>
|
||||
public ReportConsumptionProgressRequest Create(
|
||||
MediaPositionRequest? position = null,
|
||||
double? progressFraction = null,
|
||||
double? consumedDurationInSeconds = null,
|
||||
int? consecutivePagesRead = null,
|
||||
bool includePosition = true)
|
||||
{
|
||||
return new ReportConsumptionProgressRequest(
|
||||
Position: includePosition ? (position ?? _mediaPositionRequestFixture.Create()) : null,
|
||||
ProgressFraction: progressFraction ?? _faker.Random.Double(0, 1),
|
||||
ConsumedDurationInSeconds: consumedDurationInSeconds ?? _faker.Random.Double(0, 100000),
|
||||
ConsecutivePagesRead: consecutivePagesRead ?? _faker.Random.Int(0, 1000)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ReportConsumptionProgressRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ReportConsumptionProgressRequest"/> instances.</returns>
|
||||
public List<ReportConsumptionProgressRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.Requests.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="StopConsumptionRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StopConsumptionRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaPositionRequestFixture _mediaPositionRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="StopConsumptionRequest"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="position">Optional final position reported for the media item.</param>
|
||||
/// <param name="progressFraction">Optional fraction of the media item that the client reached, between 0 and 1.</param>
|
||||
/// <param name="consumedDurationInSeconds">Optional active duration consumed by the session, in seconds.</param>
|
||||
/// <param name="consecutivePagesRead">Optional number of consecutive pages read in the session.</param>
|
||||
/// <param name="includePosition">Whether the position should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeConsecutivePagesRead">Whether the number of consecutive pages read should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>A configured <see cref="StopConsumptionRequest"/> instance.</returns>
|
||||
public StopConsumptionRequest Create(
|
||||
MediaPositionRequest? position = null,
|
||||
double? progressFraction = null,
|
||||
double? consumedDurationInSeconds = null,
|
||||
int? consecutivePagesRead = null,
|
||||
bool includePosition = true,
|
||||
bool includeConsecutivePagesRead = true)
|
||||
{
|
||||
return new StopConsumptionRequest(
|
||||
Position: includePosition ? (position ?? _mediaPositionRequestFixture.Create()) : null,
|
||||
ProgressFraction: progressFraction ?? _faker.Random.Double(0, 1),
|
||||
ConsumedDurationInSeconds: consumedDurationInSeconds ?? _faker.Random.Double(0, 100000),
|
||||
ConsecutivePagesRead: includeConsecutivePagesRead ? (consecutivePagesRead ?? _faker.Random.Int(0, 1000)) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="StopConsumptionRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="StopConsumptionRequest"/> instances.</returns>
|
||||
public List<StopConsumptionRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user