Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2016 07:28
Embed
What would you like to do?
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