-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsumerTests.cs
92 lines (79 loc) · 2.23 KB
/
ConsumerTests.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
namespace Tests;
public class ConsumerTests
{
#region ConsumerTestAsserts
[Fact]
public async Task TestWithAsserts()
{
using var harness = new InMemoryTestHarness();
var consumerHarness = harness.Consumer<SubmitOrderConsumer>();
await harness.Start();
try
{
await harness.InputQueueSendEndpoint
.Send(
new SubmitOrder
{
OrderId = InVar.Id
});
// did the endpoint consume the message
Assert.True(await harness.Consumed.Any<SubmitOrder>());
// did the actual consumer consume the message
Assert.True(await consumerHarness.Consumed.Any<SubmitOrder>());
// the consumer publish the event
Assert.True(await harness.Published.Any<OrderSubmitted>());
// ensure that no faults were published by the consumer
Assert.False(await harness.Published.Any<Fault<SubmitOrder>>());
}
finally
{
await harness.Stop();
}
}
#endregion
#region ConsumerTestVerify
[Fact]
public async Task TestWithVerify()
{
using var harness = new InMemoryTestHarness();
var consumer = harness.Consumer<SubmitOrderConsumer>();
await harness.Start();
try
{
await harness.InputQueueSendEndpoint
.Send(
new SubmitOrder
{
OrderId = InVar.Id
});
await Verify(new
{
harness,
consumer
});
}
finally
{
await harness.Stop();
}
}
#endregion
public class SubmitOrder
{
public Guid OrderId { get; init; }
}
public class OrderSubmitted
{
public Guid OrderId { get; init; }
}
class SubmitOrderConsumer :
IConsumer<SubmitOrder>
{
public Task Consume(ConsumeContext<SubmitOrder> context) =>
context.Publish(
new OrderSubmitted
{
OrderId = context.Message.OrderId
});
}
}