/
TestKitBase_ActorOf.cs
360 lines (333 loc) · 19.3 KB
/
TestKitBase_ActorOf.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//-----------------------------------------------------------------------
// <copyright file="TestKitBase_ActorOf.cs" company="Akka.NET Project">
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Linq.Expressions;
using Akka.Actor;
using Akka.Actor.Dsl;
namespace Akka.TestKit
{
/// <summary>
/// TBD
/// </summary>
public partial class TestKitBase
{
private const IActorRef NoSupervisor = null;
/// <summary>
/// Create a new actor as child of <see cref="Sys" />.
/// </summary>
/// <param name="props">The props configuration object</param>
/// <returns>TBD</returns>
public IActorRef ActorOf(Props props)
{
return Sys.ActorOf(props, null);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys" />.
/// </summary>
/// <param name="props">The props configuration object</param>
/// <param name="name">The name of the actor.</param>
/// <returns>TBD</returns>
public IActorRef ActorOf(Props props, string name)
{
return Sys.ActorOf(props, name);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys" />.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <returns>TBD</returns>
public IActorRef ActorOf<TActor>() where TActor : ActorBase, new()
{
return Sys.ActorOf(Props.Create<TActor>(), null);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys" />.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <param name="name">The name of the actor.</param>
/// <returns>TBD</returns>
public IActorRef ActorOf<TActor>(string name) where TActor : ActorBase, new()
{
return Sys.ActorOf(Props.Create<TActor>(), name);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys" /> using an expression that calls the constructor
/// of <typeparamref name="TActor"/>.
/// <example>
/// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711))</code>
/// </example>
/// </summary>
/// <typeparam name="TActor">The type of the actor.</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param>
/// <returns>TBD</returns>
public IActorRef ActorOf<TActor>(Expression<Func<TActor>> factory) where TActor : ActorBase
{
return Sys.ActorOf(Props.Create(factory), null);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys" /> using an expression that calls the constructor
/// of <typeparamref name="TActor"/>.
/// <example>
/// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")</code>
/// </example>
/// </summary>
/// <typeparam name="TActor">The type of the actor.</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param>
/// <param name="name">The name of the actor.</param>
/// <returns>TBD</returns>
public IActorRef ActorOf<TActor>(Expression<Func<TActor>> factory, string name) where TActor : ActorBase
{
return Sys.ActorOf(Props.Create(factory), name);
}
/// <summary>
/// Creates a new actor by defining the behavior inside the <paramref name="configure"/> action.
/// <example>
/// <code>
/// ActorOf(c =>
/// {
/// c.Receive<string>((msg, ctx) => ctx.Sender.Tell("Hello " + msg));
/// });
/// </code>
/// </example>
/// </summary>
/// <param name="configure">An action that configures the actor's behavior.</param>
/// <param name="name">Optional: The name of the actor.</param>
/// <returns>TBD</returns>
public IActorRef ActorOf(Action<IActorDsl, IActorContext> configure, string name = null)
{
return ActExtensions.ActorOf(this, configure, name);
}
/// <summary>
/// Creates a new actor by defining the behavior inside the <paramref name="configure"/> action.
/// <example>
/// <code>
/// ActorOf(c =>
/// {
/// c.Receive<string>((msg, ctx) => ctx.Sender.Tell("Hello " + msg));
/// });
/// </code>
/// </example>
/// </summary>
/// <param name="configure">An action that configures the actor's behavior.</param>
/// <param name="name">Optional: The name of the actor.</param>
/// <returns>TBD</returns>
public IActorRef ActorOf(Action<IActorDsl> configure, string name = null)
{
return ActExtensions.ActorOf(this, configure, name);
}
/// <summary>
/// Creates an <see cref="ActorSelection(Akka.Actor.ActorPath)"/>
/// </summary>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(ActorPath actorPath)
{
return Sys.ActorSelection(actorPath);
}
///<summary>
/// Creates an <see cref="ActorSelection(string)"/>
/// </summary>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(string actorPath)
{
return Sys.ActorSelection(actorPath);
}
/// <summary>
/// Creates an <see cref="ActorSelection(string)"/>
/// </summary>
/// <param name="anchorRef">The base actor that anchors the <paramref name="actorPath"/>.</param>
/// <param name="actorPath">The path of the actor(s) we want to select.</param>
/// <returns>An ActorSelection</returns>
public ActorSelection ActorSelection(IActorRef anchorRef, string actorPath)
{
return Sys.ActorSelection(anchorRef, actorPath);
}
/// <summary>
/// Create a new actor as child of specified supervisor and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <param name="props">The <see cref="Props"/> object</param>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Props props, IActorRef supervisor, string name = null) where TActor : ActorBase
{
return new TestActorRef<TActor>(Sys, props, supervisor, name);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <param name="props">The <see cref="Props"/> object</param>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Props props, string name = null) where TActor : ActorBase
{
return new TestActorRef<TActor>(Sys, props, NoSupervisor, name);
}
/// <summary>
/// Create a new actor as child of the specified supervisor and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// Uses an expression that calls the constructor of <typeparamref name="TActor"/>.
/// <example>
/// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")</code>
/// </example>
/// </summary>
/// <typeparam name="TActor">The type of the actor.</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>> factory, IActorRef supervisor, string name = null) where TActor : ActorBase
{
return new TestActorRef<TActor>(Sys, Props.Create(factory), supervisor, name);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// Uses an expression that calls the constructor of <typeparamref name="TActor"/>.
/// <example>
/// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")</code>
/// </example>
/// </summary>
/// <typeparam name="TActor">The type of the actor.</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>> factory, string name = null) where TActor : ActorBase
{
return new TestActorRef<TActor>(Sys, Props.Create(factory), NoSupervisor, name);
}
/// <summary>
/// Create a new actor as child of the specified supervisor and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(IActorRef supervisor, string name = null) where TActor : ActorBase, new()
{
return new TestActorRef<TActor>(Sys, Props.Create<TActor>(), supervisor, name);
}
/// <summary>
/// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/>
/// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>.
/// </summary>
/// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <param name="name">Optional: The name.</param>
/// <returns>TBD</returns>
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(string name = null) where TActor : ActorBase, new()
{
return new TestActorRef<TActor>(Sys, Props.Create<TActor>(), NoSupervisor, name);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of the specified supervisor
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor. It must be a <see cref="FSM{TState,TData}"/></typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="props">The <see cref="Props"/> object</param>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props props, IActorRef supervisor, string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys, props, supervisor, name, withLogging);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/>
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor. It must be a <see cref="FSM{TState,TData}"/> and have a public parameterless constructor</typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="props">The <see cref="Props"/> object</param>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props props, string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys, props,NoSupervisor, name, withLogging);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of the specified supervisor
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// <typeparamref name="TFsmActor"/> must have a public parameterless constructor.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(IActorRef supervisor, string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>, new()
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys,Props.Create<TFsmActor>(), supervisor, name, withLogging);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/>
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// <typeparamref name="TFsmActor"/> must have a public parameterless constructor.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor. It must have a parameterless public constructor</typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>, new()
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys, Props.Create<TFsmActor>(), NoSupervisor, name, withLogging);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of the specified supervisor
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// Uses an expression that calls the constructor of <typeparamref name="TFsmActor"/>.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor.</typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TFsmActor"/></param>
/// <param name="supervisor">The supervisor</param>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>> factory, IActorRef supervisor, string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys, Props.Create(factory), supervisor, name, withLogging);
}
/// <summary>
/// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/>
/// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly.
/// Uses an expression that calls the constructor of <typeparamref name="TFsmActor"/>.
/// </summary>
/// <typeparam name="TFsmActor">The type of the actor.</typeparam>
/// <typeparam name="TState">The type of state name</typeparam>
/// <typeparam name="TData">The type of state data</typeparam>
/// <param name="factory">An expression that calls the constructor of <typeparamref name="TFsmActor"/></param>
/// <param name="name">Optional: The name.</param>
/// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param>
/// <returns>TBD</returns>
public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>> factory, string name = null, bool withLogging = false)
where TFsmActor : FSM<TState, TData>
{
return new TestFSMRef<TFsmActor, TState, TData>(Sys, Props.Create(factory), NoSupervisor, name, withLogging);
}
}
}