For fakes there is built-in support; There are actually two ways to achieve this.
1) Use ShimsContext.ExecuteWithoutShims () as a wrapper for code in which you don't need padding behavior:
System.Fakes.ShimDateTime.NowGet = () =>
{
return ShimsContext.ExecuteWithoutShims(() => DateTime.Now.AddDays(-1));
};
2) Another approach is to set the gasket to zero, call the original method, and restore the gasket.
FakesDelegates.Func<DateTime> shim = null;
shim = () =>
{
System.Fakes.ShimDateTime.NowGet = null;
var value = ShimsContext.ExecuteWithoutShims(() => DateTime.Now.AddDays(-1));
System.Fakes.ShimDateTime.NowGet = shim;
return value;
};
System.Fakes.ShimDateTime.NowGet = shim;
: , . / .