Skip to content

Instantly share code, notes, and snippets.

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