我想使用 Akka.net TestKit 来编写单元测试,但我有一个问题。我有一个 SubscriptionService 类,它负责将消息传输给选定的参与者。
public class SubscriptionService : ReceiveActor
{
private readonly ActorSelection service1;
private readonly ActorSelection service2;
public SubscriptionService()
{
this.service1 = Context.ActorSelection("Service1");
this.service2 = Context.ActorSelection("Service2");
this.Receive<RequestMessage>(message => this.ProcessRequestMessage(message));
}
private void ProcessRequestMessage(RequestMessage message)
{
this.service1.Tell(message);
this.service2.Tell(message);
}
我该如何测试这种行为?我创建了这个测试,但在这个测试中我得到了异常。“附加信息:Assert.Fail 失败。失败:等待消息时超时 00:00:03 ”
[TestClass]
public class SubscriptionServiceUnitTests : TestKit
{
[TestMethod]
public void Test1()
{
var subscriptionServiceRef = this.ActorOfAsTestActorRef<SubscriptionService>("SubscriptionService");
subscriptionServiceRef.Tell(new RequestMessage());
var answer = this.ExpectMsg<RequestMessage>();
}
我的意思是如何在 Test1 方法中获取 service1 和 service2 的消息?