Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/WorkflowCore/Services/WorkflowExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private async Task DetermineNextExecutionTime(WorkflowInstance workflow, Workflo

if (workflow.Status == WorkflowStatus.Complete)
{
PublishWorkflowCompleted(workflow);
return;
}

Expand Down Expand Up @@ -265,6 +266,11 @@ private async Task DetermineNextExecutionTime(WorkflowInstance workflow, Workflo
await middlewareRunner.RunPostMiddleware(workflow, def);
}

PublishWorkflowCompleted(workflow);
}

private void PublishWorkflowCompleted(WorkflowInstance workflow)
{
_publisher.PublishNotification(new WorkflowCompleted
{
EventTimeUtc = _datetimeProvider.UtcNow,
Comment on lines +272 to 276
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PublishWorkflowCompleted method is incomplete. The WorkflowCompleted object initialization is not closed with a closing brace and semicolon, and the method body is not properly closed.

Copilot uses AI. Check for mistakes.

Expand Down
34 changes: 34 additions & 0 deletions test/WorkflowCore.UnitTests/Services/WorkflowExecutorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FluentAssertions;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Models.LifeCycleEvents;
using WorkflowCore.Services;
using Xunit;

Expand Down Expand Up @@ -403,6 +404,39 @@ public void should_process_cancellations()
A.CallTo(() => CancellationProcessor.ProcessCancellations(instance, A<WorkflowDefinition>.Ignored, A<WorkflowExecutorResult>.Ignored)).MustHaveHappened();
}

[Fact(DisplayName = "Should send notification when workflow completes")]
public void should_send_notification_when_workflow_completes()
{
//arrange
var param = A.Fake<IStepParameter>();

// build a fake EndStep
WorkflowStep step1 = A.Fake<WorkflowStep>();
A.CallTo(() => step1.InitForExecution(A<WorkflowExecutorResult>.Ignored, A<WorkflowDefinition>.Ignored,
A<WorkflowInstance>.Ignored, A<ExecutionPointer>.Ignored))
.Returns(ExecutionPipelineDirective.EndWorkflow);

Given1StepWorkflow(step1, "Workflow", 1);

var instance = new WorkflowInstance
{
WorkflowDefinitionId = "Workflow",
Version = 1,
Status = WorkflowStatus.Runnable,
NextExecution = 0,
Id = "001",
ExecutionPointers = new ExecutionPointerCollection(new List<ExecutionPointer>
{
new ExecutionPointer { Id = "1", Active = true, StepId = 0 }
})
};

//act
Subject.Execute(instance);

//assert
A.CallTo(() => EventHub.PublishNotification(A<WorkflowCompleted>.Ignored)).MustHaveHappenedOnceExactly();
}

private void Given1StepWorkflow(WorkflowStep step1, string id, int version)
{
Expand Down