Mock static property with moq

前端 未结 6 1919
我在风中等你
我在风中等你 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:02

    Using Microsoft Fakes as suggested by @Sujith is a viable solution. Here is how you actually do it:

    • Find System.Web in your reference of your test project and right click
    • Choose "Add". This adds reference System.Web.4.0.0.0.Fakes
    • Use following code:

      using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()) { System.Web.Fakes.ShimHttpRuntime.AppDomainAppVirtualPathGet = () => "/"; // Do what ever needs the faked AppDomainAppVirtualPath }

提交回复
热议问题