forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dependency workflows publishing tests
This commit introduces a new integration test for the "DependencyWorkflowsPublishing" scenario. It also adds two new JSON files, "child.json" and "parent.json" to simulate the child and parent workflows accordingly. Updates are also made to the 'Elsa.IntegrationTests.csproj' and 'ServiceProviderExtensions.cs' as a part of testing setup.
- Loading branch information
1 parent
cfac318
commit d878314
Showing
5 changed files
with
200 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
test/integration/Elsa.IntegrationTests/Scenarios/DependencyWorkflowsPublishing/Tests.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,78 @@ | ||
using Elsa.Common.Models; | ||
using Elsa.Extensions; | ||
using Elsa.Testing.Shared; | ||
using Elsa.Workflows.Contracts; | ||
using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; | ||
using Elsa.Workflows.Management.Contracts; | ||
using Elsa.Workflows.Management.Entities; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Elsa.IntegrationTests.Scenarios.DependencyWorkflowsPublishing; | ||
|
||
/// <summary> | ||
/// Contains tests for the "DependencyWorkflowsPublishing" scenario. | ||
/// </summary> | ||
public class Tests | ||
{ | ||
private readonly CapturingTextWriter _capturingTextWriter = new(); | ||
private readonly IServiceProvider _services; | ||
private readonly IWorkflowDefinitionPublisher _workflowDefinitionPublisher; | ||
private readonly IActivitySerializer _activitySerializer; | ||
private readonly IActivityVisitor _activityVisitor; | ||
private readonly IWorkflowDefinitionManager _workflowManager; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Tests"/> class. | ||
/// </summary> | ||
public Tests(ITestOutputHelper testOutputHelper) | ||
{ | ||
_services = new TestApplicationBuilder(testOutputHelper) | ||
.WithCapturingTextWriter(_capturingTextWriter) | ||
.WithWorkflowsFromDirectory("Scenarios", "DependencyWorkflowsPublishing", "Workflows") | ||
.Build(); | ||
|
||
_workflowDefinitionPublisher = _services.GetRequiredService<IWorkflowDefinitionPublisher>(); | ||
_workflowManager = _services.GetRequiredService<IWorkflowDefinitionManager>(); | ||
_activitySerializer = _services.GetRequiredService<IActivitySerializer>(); | ||
_activityVisitor = _services.GetRequiredService<IActivityVisitor>(); | ||
} | ||
|
||
/// <summary> | ||
/// When a dependency workflow is published, all consuming workflows are updated to point to the new version of the dependency. | ||
/// </summary> | ||
[Fact(DisplayName = "When a dependency workflow is published, all consuming workflows are updated to point to the new version of the dependency.")] | ||
public async Task Test1() | ||
{ | ||
await _services.PopulateRegistriesAsync(); | ||
var childDefinitionV1 = await _services.GetWorkflowDefinitionAsync("child", VersionOptions.Latest); | ||
var parentDefinition = await _services.GetWorkflowDefinitionAsync("parent", VersionOptions.Latest); | ||
var childActivityV1 = await GetChildActivityAsync(parentDefinition); | ||
|
||
// Assert initial state. | ||
Assert.Equal(1, childDefinitionV1.Version); | ||
Assert.False(parentDefinition.IsPublished); | ||
Assert.Equal(1, childActivityV1.Version); | ||
|
||
// Create a new draft for the child workflow and publish it. | ||
var childDefinitionV2 = (await _workflowDefinitionPublisher.GetDraftAsync(childDefinitionV1.DefinitionId, VersionOptions.Published))!; | ||
await _workflowDefinitionPublisher.PublishAsync(childDefinitionV2); | ||
|
||
// Update consuming workflows to point to the new version of the child workflow. | ||
await _workflowManager.UpdateReferencesInConsumingWorkflows(childDefinitionV2); | ||
|
||
// Assert that the parent workflow now points to the new version of the child workflow. | ||
parentDefinition = await _services.GetWorkflowDefinitionAsync("parent", VersionOptions.Latest); | ||
var childActivityV2 = await GetChildActivityAsync(parentDefinition); | ||
Assert.Equal(2, childActivityV2.Version); | ||
} | ||
|
||
private async Task<WorkflowDefinitionActivity> GetChildActivityAsync(WorkflowDefinition parent) | ||
{ | ||
var root = _activitySerializer.Deserialize(parent.StringData!); | ||
var graph = await _activityVisitor.VisitAsync(root); | ||
var flattenedList = graph.Flatten().ToList(); | ||
return (WorkflowDefinitionActivity)flattenedList.Single(x => x.Activity is WorkflowDefinitionActivity { WorkflowDefinitionId: "child" }).Activity; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ration/Elsa.IntegrationTests/Scenarios/DependencyWorkflowsPublishing/Workflows/child.json
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,37 @@ | ||
{ | ||
"id": "child-v1", | ||
"definitionId": "child", | ||
"name": "Child", | ||
"createdAt": "2024-02-07T14:57:47.115341+00:00", | ||
"version": 1, | ||
"toolVersion": "3.0.0.0", | ||
"variables": [], | ||
"inputs": [], | ||
"outputs": [], | ||
"outcomes": [], | ||
"customProperties": { | ||
"Elsa:WorkflowContextProviderTypes": [] | ||
}, | ||
"isReadonly": false, | ||
"isLatest": true, | ||
"isPublished": true, | ||
"options": { | ||
"usableAsActivity": true, | ||
"autoUpdateConsumingWorkflows": true | ||
}, | ||
"root": { | ||
"type": "Elsa.Flowchart", | ||
"version": 1, | ||
"id": "c22918340b6cb7cd", | ||
"nodeId": "Workflow1:c22918340b6cb7cd", | ||
"metadata": {}, | ||
"customProperties": { | ||
"source": "FlowchartJsonConverter.cs:45", | ||
"notFoundConnections": [], | ||
"canStartWorkflow": false, | ||
"runAsynchronously": false | ||
}, | ||
"activities": [], | ||
"connections": [] | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ation/Elsa.IntegrationTests/Scenarios/DependencyWorkflowsPublishing/Workflows/parent.json
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,64 @@ | ||
{ | ||
"id": "ffd312ccf7a2af4f", | ||
"definitionId": "parent", | ||
"name": "Parent", | ||
"createdAt": "2024-02-07T14:58:12.954939+00:00", | ||
"version": 1, | ||
"toolVersion": "3.0.0.0", | ||
"variables": [], | ||
"inputs": [], | ||
"outputs": [], | ||
"outcomes": [], | ||
"customProperties": { | ||
"Elsa:WorkflowContextProviderTypes": [] | ||
}, | ||
"isReadonly": false, | ||
"isLatest": true, | ||
"isPublished": false, | ||
"options": { | ||
"autoUpdateConsumingWorkflows": false | ||
}, | ||
"root": { | ||
"type": "Elsa.Flowchart", | ||
"version": 1, | ||
"id": "3535b9598a0962f0", | ||
"nodeId": "Workflow1:3535b9598a0962f0", | ||
"metadata": {}, | ||
"customProperties": { | ||
"source": "FlowchartJsonConverter.cs:45", | ||
"notFoundConnections": [], | ||
"canStartWorkflow": false, | ||
"runAsynchronously": false | ||
}, | ||
"activities": [ | ||
{ | ||
"workflowDefinitionId": "child", | ||
"workflowDefinitionVersionId": "child-v1", | ||
"latestAvailablePublishedVersion": 1, | ||
"latestAvailablePublishedVersionId": "child-v1", | ||
"id": "35525d3b78b8e518", | ||
"nodeId": "Workflow1:3535b9598a0962f0:35525d3b78b8e518", | ||
"name": "Child1", | ||
"type": "Child", | ||
"version": 1, | ||
"customProperties": { | ||
"canStartWorkflow": false, | ||
"runAsynchronously": false | ||
}, | ||
"metadata": { | ||
"designer": { | ||
"position": { | ||
"x": -95.17782592773438, | ||
"y": -137.3333282470703 | ||
}, | ||
"size": { | ||
"width": 67.78125, | ||
"height": 50 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"connections": [] | ||
} | ||
} |