-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFunctionRegistrationTests.cs
More file actions
61 lines (52 loc) · 1.9 KB
/
Copy pathFunctionRegistrationTests.cs
File metadata and controls
61 lines (52 loc) · 1.9 KB
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
using Cleipnir.ResilientFunctions.Domain;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Messaging;
using Shouldly;
namespace Cleipnir.Flows.Tests.Flows;
[TestClass]
public class FunctionRegistrationTests
{
[TestMethod]
public async Task FunctionCanBeRegisteredAndInvoked()
{
using var container = FlowsContainer.Create();
var registration = container.Functions.RegisterFunc(
"TestFlow",
inner: Task<string> (string param) => param.ToUpper().ToTask()
);
var returned = await registration.Run("SomeInstance", "hallo world");
returned.ShouldBe("HALLO WORLD");
}
[TestMethod]
public async Task FlowCanBeCreatedWithInitialState()
{
var flowsContainer = FlowsContainer.Create();
var flow = new InitialStateFlow();
var flows = flowsContainer.RegisterAnonymousFlow<InitialStateFlow, string, string>(
flowFactory: () => flow
);
await flows.Run(
"SomeInstanceId",
param: "SomeParam",
new InitialState(
[new MessageAndIdempotencyKey(new StringMessage("InitialMessageValue"))],
[new InitialEffect(0.ToEffectId(), "InitialEffectValue")]
)
);
flow.InitialEffectValue.ShouldBe("InitialEffectValue");
flow.InitialMessageValue.ShouldBe("InitialMessageValue");
}
private class InitialStateFlow : Flow<string, string>
{
public string? InitialEffectValue { get; set; }
public string? InitialMessageValue { get; set; }
public override async Task<string> Run(string _)
{
InitialEffectValue = await Capture(() => "should not be called");
var msg = await Message<StringMessage>();
InitialMessageValue = msg.Value;
return "";
}
}
private record StringMessage(string Value);
}