-
Notifications
You must be signed in to change notification settings - Fork 2
/
Without.cs
86 lines (69 loc) · 1.78 KB
/
Without.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
using Lamar;
using WithoutMediatR.RequestResponse.WithIoC;
using Xunit;
namespace WithoutMediatR.Notification.Without;
internal interface IPingNotificationHandler
{
Task NotifyPing();
}
file class Pong1 : IPingNotificationHandler
{
internal static string WasInvoked;
Task IPingNotificationHandler.NotifyPing()
{
// do work
WasInvoked = "Pong 1";
return Task.CompletedTask;
}
}
file class Pong2 : IPingNotificationHandler
{
internal static string WasInvoked;
Task IPingNotificationHandler.NotifyPing()
{
// do work
WasInvoked = "Pong 2";
return Task.CompletedTask;
}
}
file class PingNotificationComposite : IPingNotificationHandler
{
private readonly IEnumerable<IPingNotificationHandler> _handlers;
public PingNotificationComposite(IEnumerable<IPingNotificationHandler> handlers)
{
_handlers = handlers;
}
Task IPingNotificationHandler.NotifyPing()
{
_handlers.ToList().ForEach(h => h.NotifyPing());
return Task.CompletedTask;
}
}
file class Client
{
private readonly IPingNotificationHandler _handler;
internal Client(IPingNotificationHandler handler)
{
_handler = handler;
}
internal void DoWork()
{
_handler.NotifyPing();
}
}
public class Without
{
[Fact]
void notification_test()
{
IPingNotificationHandler[] handlers =
{
new Pong1(),
new Pong2()
};
var client = new Client(new PingNotificationComposite(handlers));
client.DoWork();
Assert.Equal("Pong 1", Pong1.WasInvoked);
Assert.Equal("Pong 2", Pong2.WasInvoked);
}
}