Last active
August 29, 2015 14:02
-
-
Save yuba/b3cae2f51480712636cd to your computer and use it in GitHub Desktop.
現在時刻の取得をコード中に直に書かない ref: http://qiita.com/yuba/items/f52f90c4bd249d24b7d6
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
… | |
DateTime now = timeFetcher.Get(); | |
… |
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
class Time201401010900JST: ITimeFetcher { | |
public DateTime Get() { return new DateTime(2014, 1, 1, 9, 0, 0); } | |
} | |
… | |
// アプリケーションを初期化。実行時刻は元日朝9時の設定。 | |
AppCode app = new AppCode(new Time201401010900JST()); | |
// アプリケーションをテスト | |
Test(app); | |
… |
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 interface IEnvironmentFetcher { | |
DateTime GetTime(); | |
… | |
} |
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 interface ITimeFetcher { | |
DateTime Get(); | |
} |
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 TimeFetcher: ITimeFetcher { | |
public DateTime Get() { return DateTime.Now; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment