-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new HTTP workflow tests and enhance middleware (#5908)
Introduce tests for resuming specific HTTP workflow instances. Enhanced `HttpWorkflowsMiddleware` to handle workflow instance IDs and correlation IDs for more precise control over workflow activation and resumption.
- Loading branch information
1 parent
0a76741
commit edf365b
Showing
5 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...rkflows.ComponentTests/Scenarios/HttpWorkflows/ResumeSpecificHttpWorkflowInstanceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Net; | ||
using Elsa.Workflows.Contracts; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Elsa.Workflows.ComponentTests.Scenarios.HttpWorkflows; | ||
|
||
public class ResumeSpecificHttpWorkflowInstanceTests(App app) : AppComponentTest(app) | ||
{ | ||
[Theory] | ||
[InlineData("workflowInstanceId")] | ||
[InlineData("correlationId")] | ||
public async Task ResumingSpecificWorkflow_ShouldResumeSpecifiedWorkflow(string identifierKey) | ||
{ | ||
var client = WorkflowServer.CreateHttpWorkflowClient(); | ||
|
||
// Start 3 instances. | ||
var workflowInstanceId1 = await StartWorkflowAsync(client, identifierKey); | ||
var workflowInstanceId2 = await StartWorkflowAsync(client, identifierKey); | ||
var workflowInstanceId3 = await StartWorkflowAsync(client, identifierKey); | ||
|
||
// Resume the 2nd instance. | ||
var response = await ResumeWorkflowAsync(client, identifierKey, workflowInstanceId2); | ||
|
||
// Response should be OK. | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
private async Task<string> StartWorkflowAsync(HttpClient client, string identifierKey) | ||
{ | ||
var identityGenerator = Scope.ServiceProvider.GetRequiredService<IIdentityGenerator>(); | ||
var identifierValue = identityGenerator.GenerateId(); | ||
await client.GetStringAsync($"simple-http-api/start?{identifierKey}={identifierValue}"); | ||
return identifierValue; | ||
} | ||
|
||
private async Task<HttpResponseMessage> ResumeWorkflowAsync(HttpClient client, string identifierKey, string identifierValue) | ||
{ | ||
return await client.GetAsync($"simple-http-api/resume?{identifierKey}={identifierValue}"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../Elsa.Workflows.ComponentTests/Scenarios/HttpWorkflows/Workflows/SimpleHttpApiWorkflow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Elsa.Http; | ||
using Elsa.Workflows.Activities; | ||
using Elsa.Workflows.Contracts; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Elsa.Workflows.ComponentTests.Scenarios.HttpWorkflows.Workflows; | ||
|
||
public class SimpleHttpApiWorkflow : WorkflowBase | ||
{ | ||
protected override void Build(IWorkflowBuilder builder) | ||
{ | ||
builder.Root = new Sequence | ||
{ | ||
Activities = | ||
[ | ||
new HttpEndpoint | ||
{ | ||
Path = new("simple-http-api/start"), | ||
SupportedMethods = new([HttpMethods.Get]), | ||
CanStartWorkflow = true | ||
}, | ||
new HttpEndpoint | ||
{ | ||
Path = new("simple-http-api/resume"), | ||
SupportedMethods = new([HttpMethods.Get]) | ||
} | ||
] | ||
}; | ||
} | ||
} |
File renamed without changes.