Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2016 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bd106dd4ea63d76889216421f4275028 to your computer and use it in GitHub Desktop.
Save anonymous/bd106dd4ea63d76889216421f4275028 to your computer and use it in GitHub Desktop.
Testable virtual
public class FormattingService
{
public string Format(string message)
{
return Now + ": " + message;
}
protected virtual DateTime Now => DateTime.Now;
}
internal class TestableFormattingService : FormattingService
{
private readonly DateTime _currentDate;
public TestableFormattingService(DateTime currentDate)
{
_currentDate = currentDate;
}
protected override DateTime Now => _currentDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment