Add project files.
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\common\Elsa.Testing.Shared.Integration\Elsa.Testing.Shared.Integration.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\modules\Elsa.Alterations\Elsa.Alterations.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\modules\Elsa.Workflows.Runtime\Elsa.Workflows.Runtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Workflows\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Workflows\version-1.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Workflows\version-2.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,73 @@
|
||||
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;
|
||||
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 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>();
|
||||
_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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"id": "b760f121e7dc5dae",
|
||||
"definitionId": "my-workflow",
|
||||
"name": "Version 1",
|
||||
"version": 1,
|
||||
"toolVersion": "3.0.0.0",
|
||||
"root": {
|
||||
"type": "Elsa.Flowchart",
|
||||
"version": 1,
|
||||
"id": "52ae1d65f7896a9e",
|
||||
"nodeId": "Workflow1:52ae1d65f7896a9e",
|
||||
"activities": [
|
||||
{
|
||||
"text": {
|
||||
"typeName": "String",
|
||||
"expression": {
|
||||
"type": "Literal",
|
||||
"value": "Version 1"
|
||||
}
|
||||
},
|
||||
"id": "3a1ab61a351fe232",
|
||||
"nodeId": "Workflow1:52ae1d65f7896a9e:3a1ab61a351fe232",
|
||||
"name": "WriteLine1",
|
||||
"type": "Elsa.WriteLine",
|
||||
"metadata": {
|
||||
"designer": {
|
||||
"position": {
|
||||
"x": -121.796875,
|
||||
"y": 272
|
||||
},
|
||||
"size": {
|
||||
"width": 139.296875,
|
||||
"height": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"id": "4aca2e3aa79475d3",
|
||||
"definitionId": "my-workflow",
|
||||
"name": "Version 2",
|
||||
"version": 2,
|
||||
"toolVersion": "3.0.0.0",
|
||||
"root": {
|
||||
"type": "Elsa.Flowchart",
|
||||
"version": 1,
|
||||
"id": "52ae1d65f7896a9e",
|
||||
"nodeId": "Workflow1:52ae1d65f7896a9e",
|
||||
"activities": [
|
||||
{
|
||||
"text": {
|
||||
"typeName": "String",
|
||||
"expression": {
|
||||
"type": "Literal",
|
||||
"value": "Version 2"
|
||||
}
|
||||
},
|
||||
"id": "3a1ab61a351fe232",
|
||||
"nodeId": "Workflow1:52ae1d65f7896a9e:3a1ab61a351fe232",
|
||||
"name": "WriteLine1",
|
||||
"type": "Elsa.WriteLine",
|
||||
"metadata": {
|
||||
"designer": {
|
||||
"position": {
|
||||
"x": -121.796875,
|
||||
"y": 272
|
||||
},
|
||||
"size": {
|
||||
"width": 139.296875,
|
||||
"height": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user