I just started to implement unit tests (using xUnit and Moq) according to my already created project. The project makes heavy use of dependency injection through container units.
I have two services A and B. Service A is the one that is being tested in this case. Service A calls B and gives it a delegate for the internal function. This “callback” is used to notify A when a message is received that it should process.
Therefore, A calls (where b is an instance of service B):
b.RegisterHandler(Guid id, Action<byte[]> messageHandler);
In order to check Service A, I need to call messageHandler, as this is the only way it currently receives messages.
Can this be done with Moq? i.e. Can I laugh at service B so that when I call, the RegisterHandlervalue is messageHandlerpassed to my test?
Or do I need to reverse engineer this? Are there any design patterns I should use in this case? Does anyone know of any good resources for such a design?
source
share