Recently, I\'ve begun to use Moq to unit test. I use Moq to mock out classes that I don\'t need to test.
How do you typically deal with static methods?
There is possibility in .NET excluding MOQ and any other mocking library. You have to right click on solution explorer on assembly containing static method you want to mock and choose Add Fakes Assembly. Next you can freely mock that's assembly static methods.
Assume that you want to mock System.DateTime.Now
static method. Do this for instance this way:
using (ShimsContext.Create())
{
System.Fakes.ShimDateTime.NowGet = () => new DateTime(1837, 1, 1);
Assert.AreEqual(DateTime.Now.Year, 1837);
}
You have similar property for each static property and method.