-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
EventBusTests.cs
60 lines (49 loc) · 1.56 KB
/
EventBusTests.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
using FastEndpoints;
using Shared;
using TestCases.EventBusTest;
using Xunit;
namespace EventBus;
public class EventBusTests : TestBase
{
public EventBusTests(WebFixture fixture) : base(fixture) { }
[Fact]
public async Task Original_Handler_Execution()
{
var (rsp, res) = await Web.GuestClient.GETAsync<Endpoint, int>();
rsp.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
res.Should().Be(200);
}
[Fact]
public async Task Fake_Handler_Execution()
{
var client = Web.CreateClient(s =>
{
s.RegisterTestEventHandler<TestEvent, FakeEventHandler>();
s.RegisterTestEventHandler<TestEvent, AnotherFakeEventHandler>();
});
var (rsp, res) = await client.GETAsync<Endpoint, int>();
rsp.StatusCode.Should().Be(System.Net.HttpStatusCode.OK);
FakeEventHandler.Result.Should().Be(101);
AnotherFakeEventHandler.Result.Should().Be(102);
}
[DontRegister]
sealed class FakeEventHandler : IEventHandler<TestEvent>
{
public static int Result;
public Task HandleAsync(TestEvent eventModel, CancellationToken ct)
{
Result = eventModel.Id + 1;
return Task.CompletedTask;
}
}
[DontRegister]
sealed class AnotherFakeEventHandler : IEventHandler<TestEvent>
{
public static int Result;
public Task HandleAsync(TestEvent eventModel, CancellationToken ct)
{
Result = eventModel.Id + 2;
return Task.CompletedTask;
}
}
}