How to use MassTransit test harness to test Consumer with constructor dependency injection?

陌路散爱 提交于 2021-02-08 15:14:23

问题


I have some message consumers that take dependencies through the constructor, and I would like to cover them in unit tests. Does MassTransit's test harness provide a way to register consumers with constructor parameters?


回答1:


You can specify a factory method, or a consumer factory, when creating a consumer test harness.

harness.Consumer<T>(() => new T());

You can find the three standard extension methods in the code:

https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit/Testing/ConsumerTestHarnessExtensions.cs#L35



来源:https://stackoverflow.com/questions/55169197/how-to-use-masstransit-test-harness-to-test-consumer-with-constructor-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!