Last active
November 23, 2016 22:56
-
-
Save Foovanadil/9ca4330a436fc2e94d6d to your computer and use it in GitHub Desktop.
Unit Test TimeProvider with Default Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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