How to Mock a Static Singleton?

后端 未结 7 717
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 23:05

I have number of classes I\'ve been asked to add some unit tests to with Rhino Mocks and having some issues.

First off, I know RhinoMocks doesn\'t allow for the mock

7条回答
  •  无人及你
    2020-12-15 23:19

    Here's a low-touch approach that uses a delegate, which can be set initially and changed at runtime. It's better explained by example (specifically, mocking DateTime.Now):

    http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/11/09/systemtime-versus-isystemclock-dependencies-revisited.aspx

提交回复
热议问题