To test a code that depends on the System.DateTime
, the system.dll
must be mocked.
There are two framework that I know of that does this. Microsoft fakes and Smocks.
Microsoft fakes require visual studio 2012 ultimatum and works straight out of the compton.
Smocks is an open source and very easy to use. It can be downloaded using NuGet.
The following shows a mock of System.DateTime
:
Smock.Run(context =>
{
context.Setup(() => DateTime.Now).Returns(new DateTime(2000, 1, 1));
// Outputs "2000"
Console.WriteLine(DateTime.Now.Year);
});