-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHttpActionTests.cs
126 lines (108 loc) · 4.15 KB
/
HttpActionTests.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using DSM.Common;
using DSM.Metadata.Actions;
using DSM.Metadata.States;
using System.Threading.Tasks;
namespace DSM.Tests
{
[TestClass]
public partial class HttpActionTests : TestBase
{
[TestMethod]
[TestScaffold]
public async Task HttpPost(ScaffoldFactoryDelegate factory, string _)
{
var listenerTask = Task.Run(() => InProcWebServer.EchoAsync("http://localhost:4444/"));
var machine = new StateMachine<bool>
{
Id = "test",
States =
{
new AtomicState<bool>
{
Id = "state1",
OnEntry = new OnEntryExit<bool>
{
Actions =
{
new SendMessage<bool>
{
Id = "test-post",
ActivityType = "http-post",
Configuration = new HttpSendMessageConfiguration
{
Uri = "http://localhost:4444/",
Content = new { value = 5 }
}
}
}
},
Transitions =
{
new Transition<bool> { Target = "alldone" }
}
},
new FinalState<bool>
{
Id = "alldone"
}
}
};
var tuple = factory(machine, null, Logger);
var context = tuple.Item1;
await context.RunAsync(true);
var jsonResult = await listenerTask;
var content = JsonConvert.DeserializeAnonymousType(jsonResult, new { value = default(int) });
Assert.AreEqual(5, content.value);
}
[TestMethod]
[TestScaffold]
public async Task HttpGet(ScaffoldFactoryDelegate factory, string _)
{
var uri = "http://localhost:4444/";
var listenerTask = Task.Run(() => InProcWebServer.JsonResultAsync(uri, new { value = 43 }));
var machine = new StateMachine<(string x, string y)>
{
Id = "test",
States =
{
new AtomicState<(string x, string y)>
{
Id = "state1",
OnEntry = new OnEntryExit<(string x, string y)>
{
Actions =
{
new Query<(string x, string y)>
{
ActivityType = "http-get",
AssignTo = d => d.x,
Configuration = new HttpQueryConfiguration
{
Uri = "http://localhost:4444/"
}
}
}
},
Transitions =
{
new Transition<(string x, string y)> { Target = "alldone" }
}
},
new FinalState<(string x, string y)>
{
Id = "alldone"
}
}
};
(string x, string y) data = ("", "");
var tuple = factory(machine, null, Logger);
var context = tuple.Item1;
var task = context.RunAsync(data);
await Task.WhenAll(task, listenerTask);
var content = JsonConvert.DeserializeAnonymousType(task.Result.x, new { value = default(int) });
Assert.AreEqual(43, content.value);
}
}
}