Skip to content

Instantly share code, notes, and snippets.

@Foovanadil
Last active November 23, 2016 22:56
Show Gist options
  • Save Foovanadil/9ca4330a436fc2e94d6d to your computer and use it in GitHub Desktop.
Save Foovanadil/9ca4330a436fc2e94d6d to your computer and use it in GitHub Desktop.
Unit Test TimeProvider with Default Implementation
public abstract class TimeProvider
{
private static TimeProvider current = DefaultTimeProvider.Instance;
public static TimeProvider Current
{
get { return current; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
current = value;
}
}
public abstract DateTime UtcNow { get; }
public static void ResetToDefault()
{
current = DefaultTimeProvider.Instance;
}
}
public class DefaultTimeProvider : TimeProvider
{
private static TimeProvider instance;
public static TimeProvider Instance
{
get { return instance ?? (instance = new DefaultTimeProvider()); }
}
private DefaultTimeProvider()
{
}
public override DateTime UtcNow
{
get { return DateTime.UtcNow; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment