Mock static property with moq

前端 未结 6 1941
我在风中等你
我在风中等你 2020-11-28 08:37

I am pretty new to use moq. I am into creating some unit test case to HttpModule and everything works fine until I hit a static property as follows

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 09:13

    As mentioned in previous answers, you can't use MoQ on static methods, and if you need to, your best shot is to create a wrapper around the static class.

    However, something I've discovered recently is the Moles project. From the homepage; "Moles allows to replace any .NET method with a delegate. Moles supports static or non-virtual methods." It might be useful for your current situation.

提交回复
热议问题