ServiceRuntime.RegisterServiceAsync("MyServiceType", context =>
{
IReliableStateManager stateManager = new ReliableStateManager(context);
return new MyService(stateManager);
}
So you can IStateManager is simulated in the unit test.
For stateful actors, this seems impossible. IActorStateManager has only one internal implementation: Microsoft.ServiceFabric.Actors.Runtime.ActorStateManager. So how do I treat one What about stateful actors for unit testing?
At some point in my actor method, IActorStateManager is called, but since I cannot inject this dependency, unit testing seems impossible.
p>
Is there a way to solve this problem or is there another solution?
For Azure Service Fabric state services, IReliableStateManager can be injected as follows:
ServiceRuntime.RegisterServiceAsync ("MyServiceType", context =>
{
IReliableStateManager stateManager = new ReliableStateManage r(context);
return new MyService(stateManager);
}
So you can simulate IStateManager in the unit test of MyService.
For state actors, this seems impossible. IActorStateManager has only one internal implementation: Microsoft.ServiceFabric.Actors.Runtime.ActorStateManager. So how do I unit test a stateful actor?
At some point in my actor method, IActorStateManager is called, but since I cannot inject this dependency, unit testing seems impossible.
Is there a way to solve this? Is there another solution to this problem?
No, IActorStateManager cannot be injected today, but we are working hard to implement it. Now (without using reflection) you have to wrap your state operations where you can inject And call the call to the state manager, and then you can simulate it for unit testing.