• Roy, Awesome list. I like the practical examples - If you're doing this, it's wrong because...

    The last one was also a big "ohhhh that makes so much sense!"

  • Do you mean "DateTime.Now" or all "DateTimes"? If all "DateTimes", can you explain what the alternative would be? It seems like there would be plenty of cases where you need to pass in a DateTime to a method being tested, etc.

  • Daniel: I mean DateTime.Now and the like, not any DateTime that is hard coded such as new datetime(2000,1,1).
    any dateTime which you have no control of, basically.

    (FYI - you can use Isolator to make DateTime.Now return a custom date - just sayin!)

  • Nice list.

    Especially liked "DateTime." at the top of the list.

  • Anytime I write a test involving any kind of formatting (string, number, or date/time), I put the following lines in my test initialization method, to make sure the tests are portable:

    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

  • @John
    Most culture problems I've seen stem from the code assuming a culture (usually US). Setting up your tests like this will hide these sort of problems. Ideally you want to test against different cultures.

    try the turkish test:
    Thread.CurrentThread.CurrentCulture = GetCultureInfo("tr-TR");

    Or better still, assign it sequentially from a list of cultures that you're prepared to support. Perhaps even pick one at random each time tests run, so your tests fail at least sometimes, but don't bust-a-gut exhaustively testing every function under every culture.

  • * putting on my fire retardant suit *

    Question - how would one go about handling a class that takes in a handful of dependencies in the ctor and the behavior of that class (SUT) depends combinations of
    a) if some of the injected dependencies were called (verify)
    b) the results, if any, of those calls to your injected dependencies (multiple mocks)

    I ask because I'm wondering if I'm up against a design smell in my current situation.

Comments have been disabled for this content.