-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathITestProbe.cs
More file actions
221 lines (196 loc) · 8.58 KB
/
ITestProbe.cs
File metadata and controls
221 lines (196 loc) · 8.58 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// -----------------------------------------------------------------------
// <copyright file="ITestProbe.cs" company="Asynkron AB">
// Copyright (C) 2015-2025 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Threading;
using System.Threading.Tasks;
using Proto;
using Proto.Mailbox;
namespace Proto.TestKit;
/// <summary>
/// a test probe for intercepting messages
/// </summary>
public interface ITestProbe
{
/// <summary>
/// the sender of the last message retrieved from GetNextMessageAsync or FishForMessageAsync
/// </summary>
PID? Sender { get; }
/// <summary>
/// the context of the test probe
/// </summary>
IContext? Context { get; }
/// <summary>
/// asynchronously checks that no message arrives within the time allowed
/// </summary>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectNoMessageAsync(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<object?> GetNextMessageAsync(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextMessageAsync<T>(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously gets the next system message of type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The system message type</typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextSystemMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) where T : SystemMessage;
/// <summary>
/// asynchronously gets the next user message of type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The user message type</typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextUserMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously gets the next system message of type <typeparamref name="T"/> satisfying a predicate
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextSystemMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) where T : SystemMessage;
/// <summary>
/// asynchronously gets the next user message of type <typeparamref name="T"/> satisfying a predicate
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextUserMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously expects the next system message of type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The system message type</typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectNextSystemMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) where T : SystemMessage;
/// <summary>
/// asynchronously expects the next user message of type <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The user message type</typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectNextUserMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously expects the next system message of type <typeparamref name="T"/> satisfying a predicate
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectNextSystemMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) where T : SystemMessage;
/// <summary>
/// asynchronously expects the next user message of type <typeparamref name="T"/> satisfying a predicate
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectNextUserMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// ensures that the probe mailbox is empty
/// </summary>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
Task ExpectEmptyMailboxAsync(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously fishes for the next message of a given type from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> FishForMessageAsync<T>(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);
/// <summary>
/// asynchronously fishes for the next message of a given type from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> FishForMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);
/// <summary>
/// sends a message from the test probe to the target
/// </summary>
/// <param name="target"></param>
/// <param name="message"></param>
void Send(PID target, object message);
/// <summary>
/// responds to the current sender
/// </summary>
/// <param name="message"></param>
void Respond(object message);
/// <summary>
/// sends a request message from the test probe to the target
/// </summary>
/// <param name="target"></param>
/// <param name="message"></param>
void Request(PID target, object message);
/// <summary>
/// requests a message from the target
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="target"></param>
/// <param name="message"></param>
/// <returns></returns>
Task<T> RequestAsync<T>(PID target, object message);
/// <summary>
/// requests a message from the target
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="target"></param>
/// <param name="message"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> RequestAsync<T>(PID target, object message, CancellationToken cancellationToken);
/// <summary>
/// requests a message from the target
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="target"></param>
/// <param name="message"></param>
/// <param name="timeAllowed"></param>
/// <returns></returns>
Task<T> RequestAsync<T>(PID target, object message, TimeSpan timeAllowed);
}