mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Adds the scheduling module tests and centralizes domain event test fixtures
This commit is contained in:
1 parent
237be9e2c8
commit
99a6159f7f
135 files changed
+10203
-165
No files matched your search
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.AddScheduledJob;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.AddScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddScheduledJobCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddScheduledJobCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to add a scheduled job.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the scheduled job.</param>
|
||||
/// <param name="taskType">Optional. The type of the task executed by the scheduled job.</param>
|
||||
/// <param name="scheduleType">Optional. The type of the schedule of the scheduled job.</param>
|
||||
/// <param name="intervalMinutes">Optional. The interval in minutes of the schedule.</param>
|
||||
/// <param name="hour">Optional. The hour of the schedule.</param>
|
||||
/// <param name="minute">Optional. The minute of the schedule.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public AddScheduledJobCommand Create(
|
||||
string? name = null,
|
||||
ScheduledTaskType? taskType = null,
|
||||
ScheduleType? scheduleType = null,
|
||||
int? intervalMinutes = null,
|
||||
int? hour = null,
|
||||
int? minute = null)
|
||||
{
|
||||
return new Faker<AddScheduledJobCommand>()
|
||||
.CustomInstantiator(f =>
|
||||
{
|
||||
ScheduleType resolvedScheduleType = scheduleType ?? f.PickRandom<ScheduleType>();
|
||||
if (resolvedScheduleType == ScheduleType.WithIntervalInMinutes)
|
||||
{
|
||||
return new AddScheduledJobCommand(
|
||||
name ?? f.Commerce.ProductName(),
|
||||
taskType ?? f.PickRandom<ScheduledTaskType>(),
|
||||
resolvedScheduleType,
|
||||
intervalMinutes ?? f.Random.Int(1, 1440),
|
||||
null,
|
||||
null);
|
||||
}
|
||||
return new AddScheduledJobCommand(
|
||||
name ?? f.Commerce.ProductName(),
|
||||
taskType ?? f.PickRandom<ScheduledTaskType>(),
|
||||
resolvedScheduleType,
|
||||
null,
|
||||
hour ?? f.Random.Int(0, 23),
|
||||
minute ?? f.Random.Int(0, 59));
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="AddScheduledJobCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<AddScheduledJobCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.FireScheduledJob;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.FireScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FireScheduledJobCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FireScheduledJobCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to fire the task of a scheduled job once.
|
||||
/// </summary>
|
||||
/// <param name="scheduledJobId">Optional. The Id of the scheduled job whose task is fired.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public FireScheduledJobCommand Create(
|
||||
Guid? scheduledJobId = null)
|
||||
{
|
||||
return new Faker<FireScheduledJobCommand>()
|
||||
.CustomInstantiator(f => new FireScheduledJobCommand(scheduledJobId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FireScheduledJobCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<FireScheduledJobCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.RemoveScheduledJob;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.RemoveScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RemoveScheduledJobCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RemoveScheduledJobCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to remove a scheduled job.
|
||||
/// </summary>
|
||||
/// <param name="scheduledJobId">Optional. The Id of the scheduled job to remove.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public RemoveScheduledJobCommand Create(
|
||||
Guid? scheduledJobId = null)
|
||||
{
|
||||
return new Faker<RemoveScheduledJobCommand>()
|
||||
.CustomInstantiator(f => new RemoveScheduledJobCommand(scheduledJobId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="RemoveScheduledJobCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<RemoveScheduledJobCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.StartScheduledJob;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.StartScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="StartScheduledJobCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StartScheduledJobCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to start the execution cycle of a scheduled job.
|
||||
/// </summary>
|
||||
/// <param name="scheduledJobId">Optional. The Id of the scheduled job whose execution cycle is started.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public StartScheduledJobCommand Create(
|
||||
Guid? scheduledJobId = null)
|
||||
{
|
||||
return new Faker<StartScheduledJobCommand>()
|
||||
.CustomInstantiator(f => new StartScheduledJobCommand(scheduledJobId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="StartScheduledJobCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<StartScheduledJobCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.StopScheduledJob;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.StopScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="StopScheduledJobCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StopScheduledJobCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to stop the execution cycle of a scheduled job.
|
||||
/// </summary>
|
||||
/// <param name="scheduledJobId">Optional. The Id of the scheduled job whose execution cycle is stopped.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public StopScheduledJobCommand Create(
|
||||
Guid? scheduledJobId = null)
|
||||
{
|
||||
return new Faker<StopScheduledJobCommand>()
|
||||
.CustomInstantiator(f => new StopScheduledJobCommand(scheduledJobId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="StopScheduledJobCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<StopScheduledJobCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UpdateSchedulerDisplayPreferencesCommand"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateSchedulerDisplayPreferencesCommandFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid command to update the display preferences of the scheduler page of the current user.
|
||||
/// </summary>
|
||||
/// <param name="jobTypeFilter">Optional. The type of the scheduled job tasks whose executions are shown.</param>
|
||||
/// <param name="displayTimeSpan">Optional. The displayed time span.</param>
|
||||
/// <param name="displayTimeUnit">Optional. The unit of the displayed time span.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public UpdateSchedulerDisplayPreferencesCommand Create(
|
||||
ScheduledTaskType? jobTypeFilter = null,
|
||||
int? displayTimeSpan = null,
|
||||
SchedulerDisplayTimeUnit? displayTimeUnit = null)
|
||||
{
|
||||
return new Faker<UpdateSchedulerDisplayPreferencesCommand>()
|
||||
.CustomInstantiator(f => new UpdateSchedulerDisplayPreferencesCommand(
|
||||
jobTypeFilter ?? (f.Random.Bool() ? f.PickRandom<ScheduledTaskType>() : null),
|
||||
displayTimeSpan ?? f.Random.Int(1, 24 * 60),
|
||||
displayTimeUnit ?? f.PickRandom<SchedulerDisplayTimeUnit>()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="UpdateSchedulerDisplayPreferencesCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<UpdateSchedulerDisplayPreferencesCommand> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Scheduling.Queries.GetScheduledJobHistory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Scheduling.Queries.GetScheduledJobHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetScheduledJobHistoryQuery"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetScheduledJobHistoryQueryFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid query to get the history of the executions of the tasks of scheduled jobs.
|
||||
/// </summary>
|
||||
/// <param name="from">Optional. The inclusive lower bound of the requested interval.</param>
|
||||
/// <param name="to">Optional. The inclusive upper bound of the requested interval.</param>
|
||||
/// <param name="includeFrom">Whether to include the lower bound in the query. When false, the lower bound is left unset.</param>
|
||||
/// <param name="includeTo">Whether to include the upper bound in the query. When false, the upper bound is left unset.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetScheduledJobHistoryQuery Create(
|
||||
DateTime? from = null,
|
||||
DateTime? to = null,
|
||||
bool includeFrom = true,
|
||||
bool includeTo = true)
|
||||
{
|
||||
return new Faker<GetScheduledJobHistoryQuery>()
|
||||
.CustomInstantiator(f =>
|
||||
{
|
||||
DateTime generatedFrom = f.Date.Recent(30);
|
||||
DateTime? resolvedFrom = includeFrom ? (from ?? generatedFrom) : null;
|
||||
DateTime resolvedToBase = resolvedFrom ?? generatedFrom;
|
||||
DateTime? resolvedTo = includeTo ? (to ?? f.Date.Soon(1, resolvedToBase)) : null;
|
||||
return new GetScheduledJobHistoryQuery(resolvedFrom, resolvedTo);
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetScheduledJobHistoryQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetScheduledJobHistoryQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user