using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Models;
using Elsa.Workflows.Options;
namespace Elsa.Testing.Shared;
///
/// Provides a fake implementation of the interface,
/// designed for testing purposes. This class allows scheduling of activities within an activity execution context
/// and enables control over workflows in a simulated environment.
///
public class FakeActivityExecutionContextSchedulerStrategy : IActivityExecutionContextSchedulerStrategy
{
///
/// Schedules the provided activity for execution within the given activity execution context.
///
/// The current activity execution context in which to schedule the activity.
/// The activity to be scheduled. Can be null, in which case no operation is performed.
/// The owner activity execution context, if any.
/// Optional scheduling options to influence how the activity is scheduled.
public Task ScheduleActivityAsync(ActivityExecutionContext context, IActivity? activity, ActivityExecutionContext? owner, ScheduleWorkOptions? options = null)
{
if (activity == null)
return Task.CompletedTask;
var activityNode = new ActivityNode(activity!, "");
return ScheduleActivityAsync(context, activityNode, owner, options);
}
///
/// Schedules the provided activity for execution within the specified activity execution context using the given scheduling strategy.
///
/// The activity execution context in which the activity will be scheduled.
/// The activity node to be scheduled. If null, no operation is performed.
/// The owner activity execution context, if any, that triggered the scheduling request.
/// Optional scheduling parameters to customize the scheduling behavior.
public Task ScheduleActivityAsync(ActivityExecutionContext context, ActivityNode? activityNode, ActivityExecutionContext? owner = null, ScheduleWorkOptions? options = null)
{
if (activityNode == null)
return Task.CompletedTask;
context.WorkflowExecutionContext.Schedule(activityNode!, owner ?? context, options);
return Task.CompletedTask;
}
}