-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathScriptTransformationDispatcherTest.cs
83 lines (66 loc) · 2.78 KB
/
ScriptTransformationDispatcherTest.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
using System;
using System.Threading;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;
using IServiceOriented.ServiceBus.UnitTests;
using IServiceOriented.ServiceBus.Delivery;
using IServiceOriented.ServiceBus.Dispatchers;
namespace IServiceOriented.ServiceBus.Scripting.UnitTests
{
[TestFixture]
public class ScriptTransformationDispatcherTest
{
[Test]
public void TestPythonTransformation()
{
ScriptTransformationDispatcher dispatcher = new ScriptTransformationDispatcher("py",
@"import clr
clr.AddReference(""IServiceOriented.ServiceBus"")
clr.AddReference(""IServiceOriented.ServiceBus.Scripting.UnitTests"")
from IServiceOriented.ServiceBus import PublishRequest
from IServiceOriented.ServiceBus.Scripting.UnitTests import AfterTransformation
def Execute():
outgoing = AfterTransformation(int(request.Message.Value));
return PublishRequest(request.ContractType, request.Action, outgoing)
"
, Microsoft.Scripting.SourceCodeKind.Statements);
dispatcher.Script.Check();
dispatcher.Script.ExecuteWithVariables(new Dictionary<string,object>() {{ "request", new PublishRequest(null, null, new BeforeTransformation() { Value = "1000" }) }});
AutoResetEvent reset = new AutoResetEvent(false);
bool success = false;
ServiceBusRuntime runtime = new ServiceBusRuntime(new QueuedDeliveryCore( new NonTransactionalMemoryQueue(), new NonTransactionalMemoryQueue(), new NonTransactionalMemoryQueue() ));
runtime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Tranformation", null, null, typeof(void), dispatcher, new TypedMessageFilter(typeof(BeforeTransformation))));
runtime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "AfterTransformation", null, null, typeof(void), new ActionDispatcher( (subscription, md) =>
{
try
{
success = ((AfterTransformation)md.Message).Value == 1000;
}
finally
{
reset.Set();
}
}), new TypedMessageFilter(typeof(AfterTransformation))));
runtime.Start();
runtime.PublishOneWay(new PublishRequest(null, null, new BeforeTransformation() { Value = "1000" }));
if (!reset.WaitOne(1000 * 10, true))
{
Assert.Fail("Waited too long");
}
runtime.Stop();
}
}
public class BeforeTransformation
{
public string Value { get; set; }
}
public class AfterTransformation
{
public AfterTransformation(int value)
{
Value = value;
}
public int Value { get; set; }
}
}