Testable virtual
This file contains 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 class FormattingService | |
{ | |
public string Format(string message) | |
{ | |
return Now + ": " + message; | |
} | |
protected virtual DateTime Now => DateTime.Now; | |
} |
This file contains 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
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