elsa-core/test/integration/Elsa.Alterations.IntegrationTests/MigrationTests.cs
Sipke Schoorstra 60a349c8eb
Fix WorkflowExecutionContext bug (#4919)
* Rename Elsa.IntegrationTests to Elsa.Workflows.IntegrationTests

* Include missed files

* Update WorkflowExecutionContext to assign Activities

This commit updates the constructor of WorkflowExecutionContext. It adds a loop that iterates through each activityExecutionContext and associates its Activity with a corresponding one in the NodeIdLookup by using its NodeId as the key.

* Add versionOptions parameter to RunWorkflowUntilEndAsync method

This update introduces the versionOptions parameter to the RunWorkflowUntilEndAsync method, giving the user control over the version of the workflow they want to run. If no options are provided, the method defaults to running the published version.

* Add new integration tests and workflow samples

Created new integration test projects, Elsa.Alterations.IntegrationTests and Elsa.Workflows.IntegrationTests, for added functionality verification. Also added new workflow sample files "alteration-test.json" and "alteration-test.-v2.json" to "samples/aspnet/ElsaAlterationMigrateBug/Workflows" for testing purposes.

* Remove ElsaAlterationMigrateBug sample

This commit removes the ElsaAlterationMigrateBug sample from the project. The sample is no longer needed and its related files including workflows and project references have been deleted from the solution. This removal helps streamline the solution and remove unnecessary clutter.

* Update comment in MigrationTests.cs

The comments in the MigrationTests.cs file have been revised to provide a more accurate description of what happens in the code. The migration process described does not involve resetting execution, so any reference to it was removed.

* Refactor MigrationTests class summary description

The summary description of the MigrationTests class has been revised. The verb 'Represents' was removed to make the comment more concise and straightforward, focusing solely on its functional aspect.

* Update MigrationTests class constructor comments

The summary comments for the MigrationTests class constructor were corrected. Previously, it indicated that it represented a class containing tests for migration, which was inaccurate. It now properly describes that it initializes a new instance of the MigrationTests class.
2024-02-09 19:37:37 +01:00

76 lines
2.7 KiB
C#

using Elsa.Alterations.AlterationTypes;
using Elsa.Alterations.Core.Contracts;
using Elsa.Alterations.Extensions;
using Elsa.Common.Models;
using Elsa.Extensions;
using Elsa.Testing.Shared;
using Elsa.Workflows.Management.Contracts;
using Elsa.Workflows.Runtime.Contracts;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Alterations.IntegrationTests;
/// <summary>
/// Contains tests for migration.
/// </summary>
public class MigrationTests
{
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
private readonly IAlterationRunner _alterationRunner;
private readonly IWorkflowRuntime _workflowRuntime;
private readonly IWorkflowInstanceStore _workflowInstanceStore;
/// <summary>
/// Initializes a new instance of the <see cref="MigrationTests"/> class.
/// </summary>
public MigrationTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper)
.WithCapturingTextWriter(_capturingTextWriter)
.ConfigureElsa(elsa => elsa.UseAlterations())
.Build();
_alterationRunner = _services.GetRequiredService<IAlterationRunner>();
_workflowRuntime = _services.GetRequiredService<IWorkflowRuntime>();
_workflowInstanceStore = _services.GetRequiredService<IWorkflowInstanceStore>();
}
/// <summary>
/// This method tests the migration from version 1 to version 2.
/// </summary>
[Fact(DisplayName = "Migrating from version 1 to 2 succeeds")]
public async Task Test1()
{
// Populate registries.
await _services.PopulateRegistriesAsync();
// Import workflows.
await _services.ImportWorkflowDefinitionAsync("Workflows/version-1.json");
await _services.ImportWorkflowDefinitionAsync("Workflows/version-2.json");
// Run version 1 workflow.
var workflowState = await _services.RunWorkflowUntilEndAsync("my-workflow", versionOptions: VersionOptions.SpecificVersion(1));
// Migrate to version 2.
var alterations = new IAlteration[]
{
new Migrate
{
TargetVersion = 2
}
};
var instanceIds = new[]
{
workflowState.Id
};
var migrationResult = await _alterationRunner.RunAsync(instanceIds, alterations);
// Assert success.
Assert.True(migrationResult.All(x => x.IsSuccessful));
// Assert that the workflow instance is now at version 2.
var workflowState2 = await _workflowInstanceStore.FindAsync(workflowState.Id);
Assert.Equal(2, workflowState2!.Version);
}
}