-
Notifications
You must be signed in to change notification settings - Fork 2
/
InvokeStateMachineActionTests.cs
92 lines (84 loc) · 3.08 KB
/
InvokeStateMachineActionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DSM.Metadata.Actions;
using DSM.Metadata.States;
using System.Threading.Tasks;
namespace DSM.Tests
{
[TestClass]
public partial class InvokeStateMachineActionTests : TestBase
{
[TestMethod]
[TestScaffold]
public async Task SimpleParentChild(ScaffoldFactoryDelegate factory, string _)
{
var machine = new StateMachine<(int x, (int x, int y) innerX)>
{
Id = "outer",
States =
{
new AtomicState<(int x, (int x, int y) innerX)>
{
Id = "state1",
OnEntry = new OnEntryExit<(int x, (int x, int y) innerX)>
{
Actions =
{
new InvokeStateMachine<(int x, (int x, int y) innerX)>
{
Id = "an-invoke",
StateMachineIdentifier = "inner",
InputFunction = d => (d.x, 0),
AssignTo = d => d.innerX
}
},
},
Transitions =
{
new Transition<(int x, (int x, int y) innerX)>
{
Message = "done.invoke.*",
Target = "alldone"
}
}
},
new FinalState<(int x, (int x, int y) innerX)>
{
Id = "alldone"
}
}
};
var childMachine = new StateMachine<(int x, int y)>
{
Id = "inner",
States =
{
new AtomicState<(int x, int y)>
{
Id = "innerState1",
OnEntry = new OnEntryExit<(int x, int y)>
{
Actions =
{
new Assign<(int x, int y)> { To = d => d.x, ValueFunction = d => d.x * 2 }
}
},
Transitions =
{
new Transition<(int x, int y)> { Target = "alldone" }
}
},
new FinalState<(int x, int y)>
{
Id = "alldone"
}
}
};
(int x, (int x, int y) innerX) data = (5, (0, 0));
var tuple = factory(machine, _ => childMachine, null);
var context = tuple.Item1;
data = await context.RunAsync(data);
Assert.AreEqual(5, data.x);
Assert.AreEqual(10, data.innerX.x);
}
}
}