Skip to content

Commit 976a8ab

Browse files
committed
Added dynamic data test to WorkflowExecutorFixture
1 parent b33b86c commit 976a8ab

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/WorkflowCore.UnitTests/Services/WorkflowExecutorFixture.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,54 @@ public void should_map_outputs()
223223
data.Value1.Should().Be(7);
224224
}
225225

226+
[Fact(DisplayName = "Should map dynamic outputs")]
227+
public void should_map_outputs_dynamic()
228+
{
229+
//arrange
230+
Expression<Func<IStepWithProperties, int>> p1 = x => x.Property1;
231+
Expression<Func<DynamicDataClass, IStepExecutionContext, int>> v1 = (x, context) => x["Value1"];
232+
233+
var step1Body = A.Fake<IStepWithProperties>();
234+
A.CallTo(() => step1Body.Property1).Returns(7);
235+
A.CallTo(() => step1Body.RunAsync(A<IStepExecutionContext>.Ignored)).Returns(ExecutionResult.Next());
236+
WorkflowStep step1 = BuildFakeStep(step1Body, new List<DataMapping>(), new List<DataMapping>()
237+
{
238+
new DataMapping()
239+
{
240+
Source = p1,
241+
Target = v1
242+
}
243+
}
244+
);
245+
246+
Given1StepWorkflow(step1, "Workflow", 1);
247+
248+
var data = new DynamicDataClass()
249+
{
250+
["Value1"] = 5
251+
};
252+
253+
var instance = new WorkflowInstance
254+
{
255+
WorkflowDefinitionId = "Workflow",
256+
Version = 1,
257+
Status = WorkflowStatus.Runnable,
258+
NextExecution = 0,
259+
Id = "001",
260+
Data = data,
261+
ExecutionPointers = new List<ExecutionPointer>()
262+
{
263+
new ExecutionPointer() { Active = true, StepId = 0 }
264+
}
265+
};
266+
267+
//act
268+
Subject.Execute(instance);
269+
270+
//assert
271+
data["Value1"].Should().Be(7);
272+
}
273+
226274
[Fact(DisplayName = "Should handle step exception")]
227275
public void should_handle_step_exception()
228276
{
@@ -333,5 +381,16 @@ public class DataClass
333381
public int Value2 { get; set; }
334382
public int Value3 { get; set; }
335383
}
384+
385+
public class DynamicDataClass
386+
{
387+
public Dictionary<string, int> Storage { get; set; } = new Dictionary<string, int>();
388+
389+
public int this[string propertyName]
390+
{
391+
get => Storage[propertyName];
392+
set => Storage[propertyName] = value;
393+
}
394+
}
336395
}
337396
}

0 commit comments

Comments
 (0)