2025-04-01 05:53:00 +00:00
|
|
|
using Elsa.Workflows;
|
|
|
|
|
using Elsa.Workflows.Models;
|
|
|
|
|
using Elsa.Workflows.Options;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Testing.Shared;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides extension methods for <see cref="IServiceProvider"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[PublicAPI]
|
2025-12-19 16:05:12 +00:00
|
|
|
[Obsolete("Use WorkflowTestFixture instead.")]
|
2025-04-01 05:53:00 +00:00
|
|
|
public static class RunActivityExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <param name="services">The service provider.</param>
|
2025-12-19 16:05:12 +00:00
|
|
|
extension(IServiceProvider services)
|
2025-04-01 05:53:00 +00:00
|
|
|
{
|
2025-12-19 16:05:12 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Runs the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="activity">The activity to run.</param>
|
|
|
|
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
|
|
|
|
/// <returns>The result of running the activity.</returns>
|
|
|
|
|
[Obsolete("Use WorkflowTestFixture instead.")]
|
|
|
|
|
public async Task<RunWorkflowResult> RunActivityAsync(IActivity activity, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await services.PopulateRegistriesAsync();
|
|
|
|
|
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
|
|
|
|
var result = await workflowRunner.RunAsync(activity, cancellationToken: cancellationToken);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2025-04-01 05:53:00 +00:00
|
|
|
|
2025-12-19 16:05:12 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Runs the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="activity">The activity to run.</param>
|
|
|
|
|
/// <param name="options">A set of options.</param>
|
|
|
|
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
|
|
|
|
/// <returns>The result of running the activity.</returns>
|
|
|
|
|
[Obsolete("Use WorkflowTestFixture instead.")]
|
|
|
|
|
public async Task<RunWorkflowResult> RunActivityAsync(IActivity activity, RunWorkflowOptions options, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await services.PopulateRegistriesAsync();
|
|
|
|
|
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
|
|
|
|
var result = await workflowRunner.RunAsync(activity, options, cancellationToken);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2025-04-01 05:53:00 +00:00
|
|
|
}
|
|
|
|
|
}
|