Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/modules/Elsa.Workflows.Core/Activities/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private async Task<IEnumerable<SwitchCase>> FindMatchingCasesAsync(ExpressionExe
/// </summary>
private async ValueTask OnChildActivityCompletedAsync(ActivityCompletedContext context)
{
var scheduledActivityIds = context.TargetContext.GetProperty<HashSet<string>>("ScheduledActivityIds");
var scheduledActivityIds = context.TargetContext.GetProperty<ICollection<string>>("ScheduledActivityIds");

if (scheduledActivityIds != null
&& scheduledActivityIds.Remove(context.ChildContext.Activity.Id)
Expand Down Expand Up @@ -183,4 +183,4 @@ public SwitchCase(string label, Func<bool> condition, IActivity activity) : this
/// The activity to schedule when the condition evaluates to true.
/// </summary>
public IActivity? Activity { get; set; }
}
}
27 changes: 27 additions & 0 deletions test/unit/Elsa.Activities.UnitTests/Branching/SwitchTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Elsa.Expressions.Models;
using Elsa.Testing.Shared;
using Elsa.Workflows;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;

namespace Elsa.Activities.UnitTests.Branching;
Expand Down Expand Up @@ -104,6 +105,32 @@ public async Task Should_Use_MatchFirst_As_Default_Mode()
Assert.Equal(firstTrueActivity, scheduledActivities.First().Activity);
}

[Fact]
public async Task Should_Complete_When_Scheduled_Activity_Ids_Are_Restored_As_List()
{
// Arrange
var childActivity = new WriteLine("Child") { Id = "child" };
var switchActivity = new Switch
{
Cases = new List<SwitchCase>
{
new("True", Expression.LiteralExpression(true), childActivity)
}
};
var fixture = new ActivityTestFixture(switchActivity)
.ConfigureServices(services => services.AddSingleton<IWorkflowExecutionContextSchedulerStrategy, WorkflowExecutionContextSchedulerStrategy>());
var targetContext = await fixture.ExecuteAsync();
var callbackEntry = targetContext.WorkflowExecutionContext.CompletionCallbacks.Single();
var childContext = await targetContext.WorkflowExecutionContext.CreateActivityExecutionContextAsync(childActivity);
targetContext.SetProperty("ScheduledActivityIds", new List<string> { childActivity.Id });

// Act
await callbackEntry.CompletionCallback!(new ActivityCompletedContext(targetContext, childContext));

// Assert
Assert.Equal(ActivityStatus.Completed, targetContext.Status);
}

[Theory]
[InlineData(SwitchMode.MatchFirst)]
[InlineData(SwitchMode.MatchAny)]
Expand Down