Skip to content

Commit 6d849ab

Browse files
committed
Added Tests for persistence with dynamic data
1 parent ab2fb08 commit 6d849ab

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using FluentAssertions;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
using WorkflowCore.Testing;
7+
using Xunit;
8+
9+
namespace WorkflowCore.IntegrationTests.Scenarios
10+
{
11+
public class DynamicDataIOScenario : WorkflowTest<DynamicDataIOScenario.DataIOWorkflow, DynamicDataIOScenario.MyDataClass>
12+
{
13+
public class AddNumbers : StepBody
14+
{
15+
public int Input1 { get; set; }
16+
public int Input2 { get; set; }
17+
public int Output { get; set; }
18+
19+
public override ExecutionResult Run(IStepExecutionContext context)
20+
{
21+
Output = (Input1 + Input2);
22+
return ExecutionResult.Next();
23+
}
24+
}
25+
26+
public class MyDataClass
27+
{
28+
public int Value1 { get; set; }
29+
public int Value2 { get; set; }
30+
31+
public Dictionary<string, int> _storage = new Dictionary<string, int>();
32+
33+
public int this[string propertyName]
34+
{
35+
get => _storage[propertyName];
36+
set => _storage[propertyName] = value;
37+
}
38+
}
39+
40+
public class DataIOWorkflow : IWorkflow<MyDataClass>
41+
{
42+
public string Id => "DataIOWorkflow";
43+
public int Version => 1;
44+
public void Build(IWorkflowBuilder<MyDataClass> builder)
45+
{
46+
builder
47+
.StartWith<AddNumbers>()
48+
.Input(step => step.Input1, data => data.Value1)
49+
.Input(step => step.Input2, data => data.Value2)
50+
.Output(data => data["Value3"], step => step.Output);
51+
}
52+
}
53+
54+
public DynamicDataIOScenario()
55+
{
56+
Setup();
57+
}
58+
59+
[Fact]
60+
public void Scenario()
61+
{
62+
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 });
63+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
64+
65+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
66+
UnhandledStepErrors.Count.Should().Be(0);
67+
GetData(workflowId)["Value3"].Should().Be(5);
68+
}
69+
}
70+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using WorkflowCore.IntegrationTests.Scenarios;
4+
using Xunit;
5+
6+
namespace WorkflowCore.Tests.MongoDB.Scenarios
7+
{
8+
[Collection("Mongo collection")]
9+
public class MongoDynamicDataScenario : DynamicDataIOScenario
10+
{
11+
protected override void ConfigureServices(IServiceCollection services)
12+
{
13+
services.AddWorkflow(x => x.UseMongoDB(MongoDockerSetup.ConnectionString, "integration-tests"));
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using WorkflowCore.IntegrationTests.Scenarios;
4+
using Xunit;
5+
6+
namespace WorkflowCore.Tests.PostgreSQL.Scenarios
7+
{
8+
[Collection("Postgres collection")]
9+
public class PostgresDynamicDataScenario : DynamicDataIOScenario
10+
{
11+
protected override void ConfigureServices(IServiceCollection services)
12+
{
13+
services.AddWorkflow(x => x.UsePostgreSQL(PostgresDockerSetup.ScenarioConnectionString, true, true));
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using WorkflowCore.IntegrationTests.Scenarios;
4+
using Xunit;
5+
6+
namespace WorkflowCore.Tests.SqlServer.Scenarios
7+
{
8+
[Collection("SqlServer collection")]
9+
public class SqlServerDynamicDataScenario : DynamicDataIOScenario
10+
{
11+
protected override void ConfigureServices(IServiceCollection services)
12+
{
13+
services.AddWorkflow(x => x.UseSqlServer(SqlDockerSetup.ScenarioConnectionString, true, true));
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)