Contents tagged with Unit Testing

  • Testing DateTimes (and other things) with an Ambient Context

    Tags: patterns, TDD, Unit Testing

    One issue you’re likely to face while writing automated tests is that it can be tricky to check anything related to DateTimes, as they are typically accessed statically using:

    var startTime = DateTime.Now;

    The approach I’ve typically used is to create some kind of IDateProvider interface, and supply that as a dependency as needed using Dependency Injection.  However, with things used throughout a system like DateTime can be, this becomes quite a chore and make the code more complex with an ever-increasing list of dependencies.