using Elsa.Workflows; namespace Elsa.Testing.Shared; /// /// Provides extension methods for to enhance its functionality. /// public static class ActivityExecutionContextExtensions { /// /// Determines whether the specified activity is scheduled in the workflow execution context. /// /// The activity execution context instance used for checking the scheduled activity. /// The activity to check for scheduling. /// True if the specified activity is scheduled; otherwise, false. public static bool HasScheduledActivity(this ActivityExecutionContext activityExecutionContext, IActivity activity) { return activityExecutionContext.WorkflowExecutionContext.Scheduler.Find(x => x.Activity == activity) != null; } /// /// Retrieves the collection of outcomes recorded in the execution context's journal data. /// /// The activity execution context from which to retrieve the outcomes. /// A collection of outcome strings, or an empty collection if no outcomes are present. public static IEnumerable GetOutcomes(this ActivityExecutionContext activityExecutionContext) { return activityExecutionContext.JournalData.TryGetValue("Outcomes", out var outcomes) && outcomes is string[] arr ? arr : []; } /// /// Determines whether the specified outcome exists in the current activity execution context. /// /// The activity execution context to check for the outcome. /// The outcome to verify within the execution context. /// True if the specified outcome exists; otherwise, false. public static bool HasOutcome(this ActivityExecutionContext activityExecutionContext, string outcome) { return activityExecutionContext.GetOutcomes().Contains(outcome); } }