| | | 1 | | using Elsa.Workflows; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Testing.Shared; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides extension methods for <see cref="ActivityExecutionContext"/> to enhance its functionality. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class ActivityExecutionContextExtensions |
| | | 9 | | { |
| | | 10 | | /// <param name="activityExecutionContext">The activity execution context instance used for checking the scheduled a |
| | | 11 | | extension(ActivityExecutionContext activityExecutionContext) |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Determines whether the specified activity is scheduled in the workflow execution context. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="activity">The activity to check for scheduling.</param> |
| | | 17 | | /// <returns>True if the specified activity is scheduled; otherwise, false.</returns> |
| | | 18 | | public bool HasScheduledActivity(IActivity activity) |
| | | 19 | | { |
| | 0 | 20 | | return activityExecutionContext.WorkflowExecutionContext.Scheduler.Find(x => x.Activity == activity) != null |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Retrieves the collection of outcomes recorded in the execution context's journal data. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <returns>A collection of outcome strings, or an empty collection if no outcomes are present.</returns> |
| | | 27 | | public IEnumerable<string> GetOutcomes() |
| | | 28 | | { |
| | 0 | 29 | | return activityExecutionContext.JournalData.TryGetValue("Outcomes", out var outcomes) && outcomes is string[ |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Determines whether the specified outcome exists in the current activity execution context. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="outcome">The outcome to verify within the execution context.</param> |
| | | 36 | | /// <returns>True if the specified outcome exists; otherwise, false.</returns> |
| | | 37 | | public bool HasOutcome(string outcome) |
| | | 38 | | { |
| | 0 | 39 | | return activityExecutionContext.GetOutcomes().Contains(outcome); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | } |