using Elsa.Testing.Shared; using Elsa.Workflows.Activities; using Elsa.Workflows.Contracts; using Microsoft.Extensions.DependencyInjection; using Xunit.Abstractions; namespace Elsa.Workflows.Core.UnitTests; public class ScheduleActivityExecutionContextTests(ITestOutputHelper testOutputHelper) { private readonly IServiceProvider _serviceProvider = new TestApplicationBuilder(testOutputHelper).Build(); [Fact(DisplayName = "Scheduling an activity that is not part of the workflow should throw an exception")] public async Task ScheduleActivityAsync_WithActivityNotPartOfWorkflow_ShouldThrowException() { await _serviceProvider.PopulateRegistriesAsync(); var writeLineA = new WriteLine("Test"); var writeLineB = new WriteLine("Test"); var workflow = new Workflow { Root = writeLineA }; var workflowGraphBuilder = _serviceProvider.GetRequiredService(); var workflowGraph = await workflowGraphBuilder.BuildAsync(workflow); var workflowExecutionContext = await WorkflowExecutionContext.CreateAsync(_serviceProvider, workflowGraph, "test"); var activityExecutionContext = workflowExecutionContext.CreateActivityExecutionContext(writeLineA); await Assert.ThrowsAsync(() => activityExecutionContext.ScheduleActivityAsync(writeLineB).AsTask()); } }