Mocking Static methods using Rhino.Mocks

前端 未结 6 1068
夕颜
夕颜 2020-11-29 07:14

Is it possible to mock a static method using Rhino.Mocks? If Rhino does not support this, is there a pattern or something which would let me accomplish the same?

6条回答
  •  离开以前
    2020-11-29 07:47

    Is it possible to mock a static method using Rhino.Mocks

    No, it is not possible.

    TypeMock can do this because it utilizes the CLR profiler to intercept and redirect calls.

    RhinoMocks, NMock, and Moq cannot do this because these libraries are simpler; they don't use the CLR profiler APIs. They are simpler in that they use proxies to intercept virtual members and interface calls. The downside of this simplicity is that they cannot mock certain things, such as static methods, static properties, sealed classes, or non-virtual instance methods.

提交回复
热议问题