mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17: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
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserId"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserIdFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UserId"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The raw value of the user Id.</param>
|
||||
/// <returns>The created <see cref="UserId"/>.</returns>
|
||||
public UserId Create(
|
||||
Guid? value = null)
|
||||
{
|
||||
return UserId.Create(value ?? Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="UserId"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="UserId"/> instances.</returns>
|
||||
public List<UserId> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobAddedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobAddedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobAddedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job that was added.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobAddedDomainEvent"/>.</returns>
|
||||
public ScheduledJobAddedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobAddedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobCycleStartedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobCycleStartedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobCycleStartedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose execution cycle was started.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobCycleStartedDomainEvent"/>.</returns>
|
||||
public ScheduledJobCycleStartedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobCycleStartedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobCycleStoppedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobCycleStoppedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobCycleStoppedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose execution cycle was stopped.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobCycleStoppedDomainEvent"/>.</returns>
|
||||
public ScheduledJobCycleStoppedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobCycleStoppedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobExecutionCompletedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobExecutionCompletedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobExecutionCompletedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose task completed its execution.</param>
|
||||
/// <param name="runId">Optional. The unique identifier of the current execution of the task of the scheduled job.</param>
|
||||
/// <param name="taskType">The type of the task that completed its execution.</param>
|
||||
/// <param name="isCycleRun">Whether the execution was triggered by the execution cycle of the scheduled job.</param>
|
||||
/// <param name="completedOnUtc">Optional. The date and time when the execution completed.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobExecutionCompletedDomainEvent"/>.</returns>
|
||||
public ScheduledJobExecutionCompletedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
Guid? runId = null,
|
||||
ScheduledTaskType taskType = ScheduledTaskType.ScanMediaLibraries,
|
||||
bool isCycleRun = false,
|
||||
DateTime? completedOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobExecutionCompletedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
runId ?? Guid.NewGuid(),
|
||||
taskType,
|
||||
isCycleRun,
|
||||
completedOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobExecutionStartedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobExecutionStartedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobExecutionStartedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose task started executing.</param>
|
||||
/// <param name="runId">Optional. The unique identifier of the current execution of the task of the scheduled job.</param>
|
||||
/// <param name="taskType">The type of the task that started executing.</param>
|
||||
/// <param name="isCycleRun">Whether the execution was triggered by the execution cycle of the scheduled job.</param>
|
||||
/// <param name="startedOnUtc">Optional. The date and time when the execution started.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobExecutionStartedDomainEvent"/>.</returns>
|
||||
public ScheduledJobExecutionStartedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
Guid? runId = null,
|
||||
ScheduledTaskType taskType = ScheduledTaskType.ScanMediaLibraries,
|
||||
bool isCycleRun = false,
|
||||
DateTime? startedOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobExecutionStartedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
runId ?? Guid.NewGuid(),
|
||||
taskType,
|
||||
isCycleRun,
|
||||
startedOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobExecutionStoppedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobExecutionStoppedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobExecutionStoppedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose running execution was stopped.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobExecutionStoppedDomainEvent"/>.</returns>
|
||||
public ScheduledJobExecutionStoppedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobExecutionStoppedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobFiredDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobFiredDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobFiredDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job whose task was fired.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobFiredDomainEvent"/>.</returns>
|
||||
public ScheduledJobFiredDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobFiredDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobRemovedDomainEvent"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobRemovedDomainEventFixture
|
||||
{
|
||||
private readonly ScheduledJobIdFixture _scheduledJobIdFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobRemovedDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the domain event.</param>
|
||||
/// <param name="scheduledJobId">Optional. The unique identifier of the scheduled job that was removed.</param>
|
||||
/// <param name="occurredOnUtc">Optional. The date and time when the domain event occurred.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobRemovedDomainEvent"/>.</returns>
|
||||
public ScheduledJobRemovedDomainEvent Create(
|
||||
Guid? id = null,
|
||||
ScheduledJobId? scheduledJobId = null,
|
||||
DateTime? occurredOnUtc = null)
|
||||
{
|
||||
return new ScheduledJobRemovedDomainEvent(
|
||||
id ?? Guid.NewGuid(),
|
||||
scheduledJobId ?? _scheduledJobIdFixture.Create(),
|
||||
occurredOnUtc ?? DateTime.UtcNow);
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJob"/> domain aggregate.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobFixture
|
||||
{
|
||||
private readonly IntervalScheduleFixture _intervalScheduleFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJob"/> domain aggregate.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the scheduled job. When provided, the aggregate is created with pre-existing data.</param>
|
||||
/// <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="schedule">Optional. The schedule of the scheduled job. Defaults to an interval schedule of 60 minutes.</param>
|
||||
/// <param name="ownerUserId">Optional. The Id of the user that owns the scheduled job.</param>
|
||||
/// <param name="status">Optional. The status of the scheduled job. Only applied when <paramref name="id"/> is provided.</param>
|
||||
/// <param name="lastStartedOnUtc">Optional. The last start time of the scheduled job. Only applied when <paramref name="id"/> is provided.</param>
|
||||
/// <param name="lastCompletedOnUtc">Optional. The last completion time of the scheduled job. Only applied when <paramref name="id"/> is provided.</param>
|
||||
/// <returns>The created <see cref="ScheduledJob"/>.</returns>
|
||||
public ScheduledJob Create(
|
||||
Guid? id = null,
|
||||
string? name = null,
|
||||
ScheduledTaskType? taskType = null,
|
||||
Schedule? schedule = null,
|
||||
Guid? ownerUserId = null,
|
||||
ScheduledJobStatus? status = null,
|
||||
DateTime? lastStartedOnUtc = null,
|
||||
DateTime? lastCompletedOnUtc = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
ScheduledJobStatus resolvedStatus = status ?? ScheduledJobStatus.Added;
|
||||
string resolvedName = name ?? faker.Commerce.ProductName();
|
||||
ScheduledTaskType resolvedTaskType = taskType ?? faker.PickRandom<ScheduledTaskType>();
|
||||
UserId resolvedOwnerUserId = UserId.Create(ownerUserId ?? Guid.NewGuid());
|
||||
Schedule resolvedSchedule = schedule ?? _intervalScheduleFixture.Create(faker.Random.Int(5, 1440));
|
||||
|
||||
// When no pre-existing state is requested, create a fresh scheduled job with the default Added status.
|
||||
if (id is null && status is null)
|
||||
{
|
||||
Result<ScheduledJob> createResult = ScheduledJob.Create(resolvedName, resolvedTaskType, resolvedSchedule, resolvedOwnerUserId);
|
||||
return createResult.Value;
|
||||
}
|
||||
|
||||
// When a pre-existing Id or an explicit status is requested, create the scheduled job with that pre-existing state.
|
||||
Result<ScheduledJob> createWithIdResult = ScheduledJob.Create(
|
||||
ScheduledJobId.Create(id ?? Guid.NewGuid()),
|
||||
resolvedName,
|
||||
resolvedTaskType,
|
||||
resolvedSchedule,
|
||||
resolvedOwnerUserId,
|
||||
resolvedStatus,
|
||||
Optional<DateTime>.FromNullable(lastStartedOnUtc),
|
||||
Optional<DateTime>.FromNullable(lastCompletedOnUtc));
|
||||
return createWithIdResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ScheduledJob"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ScheduledJob"/> instances.</returns>
|
||||
public List<ScheduledJob> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="DailySchedule"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DailyScheduleFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="DailySchedule"/>.
|
||||
/// </summary>
|
||||
/// <param name="hour">Optional. The hour of the day at which the task runs.</param>
|
||||
/// <param name="minute">Optional. The minute of the hour at which the task runs.</param>
|
||||
/// <returns>The created <see cref="DailySchedule"/>.</returns>
|
||||
public DailySchedule Create(int? hour = null, int? minute = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return DailySchedule.Create(
|
||||
hour ?? faker.Random.Int(0, 23),
|
||||
minute ?? faker.Random.Int(0, 59)).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="DailySchedule"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="DailySchedule"/> instances.</returns>
|
||||
public List<DailySchedule> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="IntervalSchedule"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IntervalScheduleFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="IntervalSchedule"/>.
|
||||
/// </summary>
|
||||
/// <param name="intervalMinutes">Optional. The number of minutes between each execution.</param>
|
||||
/// <returns>The created <see cref="IntervalSchedule"/>.</returns>
|
||||
public IntervalSchedule Create(int? intervalMinutes = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return IntervalSchedule.Create(intervalMinutes ?? faker.Random.Int(1, 1440)).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="IntervalSchedule"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="IntervalSchedule"/> instances.</returns>
|
||||
public List<IntervalSchedule> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ScheduledJobId"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScheduledJobIdFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ScheduledJobId"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The raw value of the scheduled job Id.</param>
|
||||
/// <returns>The created <see cref="ScheduledJobId"/>.</returns>
|
||||
public ScheduledJobId Create(
|
||||
Guid? value = null)
|
||||
{
|
||||
return ScheduledJobId.Create(value ?? Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ScheduledJobId"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ScheduledJobId"/> instances.</returns>
|
||||
public List<ScheduledJobId> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user