我正在尝试编写一个简单的 Akka.NET 流。源是一个IActorRef
. 水槽是一个ISubscriber
. 我正在使用 TestKit 将其实现为单元测试:
[Fact]
public void AkkaStreams_ActorSourcePublisherSink_Works()
{
using (var materializer = Sys.Materializer())
{
var probe = CreateTestProbe();
var source = Source.ActorRef<HandlerErrorEvent>(10, OverflowStrategy.DropNew);
var subscriber = new Mock<ISubscriber<HandlerErrorEvent>>();
var sink = Sink.FromSubscriber<HandlerErrorEvent>(subscriber.Object);
var graph = source.ToMaterialized(sink, Keep.Both);
var (actor, publisher) = graph.Run(materializer);
subscriber.Verify(s => s.OnSubscribe(It.IsAny<ISubscription>()));
var evnt = new HandlerErrorEvent("", HandlerResult.NotHandled);
actor.Tell(evnt, ActorRefs.Nobody);
base.AwaitCondition(() =>
{
try
{
subscriber.Verify(s => s.OnNext(It.IsAny<HandlerErrorEvent>()));
return true;
}
catch(MockException)
{
return false;
}
});
}
}
对该方法的初始Verify
调用OnSubscribe
顺利通过,但模拟订阅者从未收到对OnNext
.
我究竟做错了什么?
运行为netcoreapp2.0
. 参考:
"Akka.TestKit.Xunit2" Version="1.3.2"
"Microsoft.NET.Test.Sdk" Version="15.5.0"
"Moq" Version="4.8.0-rc1"
"xunit" Version="2.3.1"
"xunit.runner.visualstudio" Version="2.3.1"
"dotnet-xunit" Version="2.3.1"