简体   繁体   English

使用Context.DI()的Akka.net测试演员

[英]Akka.net testing actor using Context.DI()

I think this should be an "easy" one. 我认为这应该是“轻松”的。 I'm trying to test the behavior of an actor that performs a child actor creation when receiving a message. 我正在尝试测试接收消息时执行子actor创建的actor的行为。 I'm using Context.DI().Props<ChildActor>() to create it and that's fine however there is an exception being thrown when I try to run the tests: 我正在使用Context.DI().Props<ChildActor>()创建它,这很好,但是当我尝试运行测试时会抛出异常:

Cause: System.NullReferenceException: Object reference not set to an instance of an object.
   at Akka.DI.Core.DIActorContextAdapter.Props[TActor]()

And I have installed the Akka.TestKit, the Akka.DI.TestKit, etc. Is there anything I need to configure/set in my test to "mock" the Context.DI()? 而且我已经安装了Akka.TestKit,Akka.DI.TestKit等。在测试中是否需要配置/设置“模拟” Context.DI()?

Thanks! 谢谢!

Akka.DI.TestKit is used to test custom IoC container plugins (like Autofac, NInject etc.) for compatibility with Akka. Akka.DI.TestKit用于测试自定义IoC容器插件(如Autofac,NInject等)与Akka的兼容性。 They are not used for testing custom code. 它们不用于测试自定义代码。

If you want to mock Context.DI() you probably need to supply container and register your mocks in it. 如果要模拟Context.DI() ,则可能需要提供容器并在其中注册模拟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM