对于Azure Service Fabric状态服务,可以按如下方式注入IReliableStateManager:
ServiceRuntime.RegisterServiceAsync("MyServiceType",context => { IReliableStateManager stateManager = new ReliableStateManager(context); return new MyService(stateManager); }
这样你就可以在MyService的单元测试中模拟IStateManager.
对于有状态的演员来说,这似乎是不可能的. IActorStateManager只有一个内部实现:Microsoft.ServiceFabric.Actors.Runtime.ActorStateManager.那么我如何对一个有状态的演员进行单元测试呢?
在我的actor方法的某个时刻,调用了IActorStateManager,但由于我不能注入这个依赖项,所以单元测试似乎是不可能的.