-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.cs
More file actions
70 lines (60 loc) · 1.86 KB
/
Tests.cs
File metadata and controls
70 lines (60 loc) · 1.86 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
62
63
64
65
66
67
68
69
70
// ReSharper disable ArrangeObjectCreationWhenTypeNotEvident
// ReSharper disable MethodSupportsCancellation
public class Tests
{
#region HandlerTest
[Fact]
public async Task HandlerTest()
{
var context = new RecordingCommandProcessor();
var handler = new Handler(context);
await handler.HandleAsync(new Message("value"));
await Verify(context);
}
#endregion
[Fact]
public async Task AllTest()
{
var context = new RecordingCommandProcessor();
var handler = new AllHandler(context);
await handler.HandleAsync(new Message("value"));
await Verify(context);
}
}
#region Handler
public class Handler(IAmACommandProcessor processor) :
RequestHandlerAsync<Message>
{
public override async Task<Message> HandleAsync(
Message message,
Cancel cancel = default)
{
await processor.SendAsync(new MyCommand("Some data"));
await processor.PublishAsync(new MyEvent("Some other data"));
return await base.HandleAsync(message);
}
}
#endregion
public class AllHandler(RecordingCommandProcessor processor) :
RequestHandlerAsync<Message>
{
public override Task<Message> HandleAsync(Message message, Cancel cancel = default)
{
processor.Send(new Response("Send Value"));
processor.Post(new Response("Post Value"));
processor.Publish(new Response("Publish Value"));
processor.DepositPost(new Response("Publish Value"));
processor.ClearOutbox([]);
processor.Call<Call, Response>(new Call(), null, TimeSpan.FromHours(1));
return base.HandleAsync(message);
}
}
public class Call :
ICall
{
public Id? CorrelationId { get; set; }
public Id Id { get; set; } = Id.Random();
public Activity Span { get; set; } = null!;
public ReplyAddress ReplyAddress { get; } = null!;
}