<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Testability Of Date-Dependent Code</title>
	<atom:link href="http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Tue, 16 Mar 2010 15:10:50 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22798</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Fri, 23 Oct 2009 06:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22798</guid>
		<description>@Eric

we don&#039;t run multiple tests simultaneously so it works... and like i said &quot;And as long as that works, resist the urge to change it.&quot;

once it stops working (like when switching to a multi threaded testrun) then you obviously change it :)</description>
		<content:encoded><![CDATA[<p>@Eric</p>
<p>we don&#8217;t run multiple tests simultaneously so it works&#8230; and like i said &#8220;And as long as that works, resist the urge to change it.&#8221;</p>
<p>once it stops working (like when switching to a multi threaded testrun) then you obviously change it <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Smith</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22797</link>
		<dc:creator>Eric Smith</dc:creator>
		<pubDate>Fri, 23 Oct 2009 05:04:22 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22797</guid>
		<description>Great idea - just one problem---you can&#039;t run multiple tests simultaneous in separate threads.  How about a [ThreadStatic] dateTimeToReturn?</description>
		<content:encoded><![CDATA[<p>Great idea &#8211; just one problem&#8212;you can&#8217;t run multiple tests simultaneous in separate threads.  How about a [ThreadStatic] dateTimeToReturn?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SeeR</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22796</link>
		<dc:creator>SeeR</dc:creator>
		<pubDate>Wed, 21 Oct 2009 22:39:09 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22796</guid>
		<description>This is what I&#039;m using

&lt;code&gt;
public class SomeClass
{
    public static Func Now = () =&gt; DateTime.Now;

    public void SomeMethod()
    {
        ...
        var x = Now().Hour;
        ...
    }
}
&lt;/code&gt;

And than I just setup SomeClass.Now in each of my tests</description>
		<content:encoded><![CDATA[<p>This is what I&#8217;m using</p>
<p><code><br />
public class SomeClass<br />
{<br />
    public static Func Now = () =&gt; DateTime.Now;</p>
<p>    public void SomeMethod()<br />
    {<br />
        ...<br />
        var x = Now().Hour;<br />
        ...<br />
    }<br />
}<br />
</code></p>
<p>And than I just setup SomeClass.Now in each of my tests</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Oliver</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22795</link>
		<dc:creator>Jonathan Oliver</dc:creator>
		<pubDate>Wed, 21 Oct 2009 15:39:11 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22795</guid>
		<description>One point I&#039;d like to mention is that of using IDisposable to ensure that the correct/real DateTime is restored at the end of your operational context.  Since posting my original article, I have create written another one introducing some open source code to address this very issue:
http://jonathan-oliver.blogspot.com/2009/10/testing-timestatic-calls-and.html

It&#039;s very similar to Mel Grubb&#039;s approach (which I have become aware of because of his comment above), the difference being that my approach stores the DateTime object on the thread-local store rather than DateTimeContext.</description>
		<content:encoded><![CDATA[<p>One point I&#8217;d like to mention is that of using IDisposable to ensure that the correct/real DateTime is restored at the end of your operational context.  Since posting my original article, I have create written another one introducing some open source code to address this very issue:<br />
<a href="http://jonathan-oliver.blogspot.com/2009/10/testing-timestatic-calls-and.html" rel="nofollow">http://jonathan-oliver.blogspot.com/2009/10/testing-timestatic-calls-and.html</a></p>
<p>It&#8217;s very similar to Mel Grubb&#8217;s approach (which I have become aware of because of his comment above), the difference being that my approach stores the DateTime object on the thread-local store rather than DateTimeContext.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mel Grubb</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22794</link>
		<dc:creator>Mel Grubb</dc:creator>
		<pubDate>Wed, 21 Oct 2009 15:27:53 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22794</guid>
		<description>Here&#039;s a third variation for you using a nestable, thread-local-storage-based &quot;context&quot; class.
http://melgrubb.spaces.live.com/blog/cns!A44BB98A805C8996!263.entry

The implementation may be more &quot;overkill&quot;, but it makes the usage nice and simple.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a third variation for you using a nestable, thread-local-storage-based &#8220;context&#8221; class.<br />
<a href="http://melgrubb.spaces.live.com/blog/cns" rel="nofollow">http://melgrubb.spaces.live.com/blog/cns</a>!A44BB98A805C8996!263.entry</p>
<p>The implementation may be more &#8220;overkill&#8221;, but it makes the usage nice and simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn Neal</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22793</link>
		<dc:creator>Shawn Neal</dc:creator>
		<pubDate>Wed, 21 Oct 2009 14:55:09 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22793</guid>
		<description>A DateTime service is overkill for most scenarios.  We do EXACTLY what you&#039;re doing with your DateTimeProvider, works like a champ.  I&#039;m just waiting for someone to write a test that forgets to reset the time provider, but that hasn&#039;t happened yet.</description>
		<content:encoded><![CDATA[<p>A DateTime service is overkill for most scenarios.  We do EXACTLY what you&#8217;re doing with your DateTimeProvider, works like a champ.  I&#8217;m just waiting for someone to write a test that forgets to reset the time provider, but that hasn&#8217;t happened yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KG2V</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22792</link>
		<dc:creator>KG2V</dc:creator>
		<pubDate>Wed, 21 Oct 2009 13:57:49 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22792</guid>
		<description>For years, I&#039;ve just gone the other way - Datetime is a passed parameter</description>
		<content:encoded><![CDATA[<p>For years, I&#8217;ve just gone the other way &#8211; Datetime is a passed parameter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22791</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 21 Oct 2009 13:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22791</guid>
		<description>@Urs

did you read the first part of the post? :P</description>
		<content:encoded><![CDATA[<p>@Urs</p>
<p>did you read the first part of the post? <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Urs Enzler</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22790</link>
		<dc:creator>Urs Enzler</dc:creator>
		<pubDate>Wed, 21 Oct 2009 13:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22790</guid>
		<description>Furthermore, I would suggest to not use a singleton but pass the service to its client with dependency injection.</description>
		<content:encoded><![CDATA[<p>Furthermore, I would suggest to not use a singleton but pass the service to its client with dependency injection.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22788</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 21 Oct 2009 09:53:16 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22788</guid>
		<description>I posted about this topic a while back &lt;a&gt;http://journalofasoftwaredev.wordpress.com/2009/01/31/obstacles-of-unit-testing-methods-to-side-step-them-part-1-date-and-time/&lt;/a&gt; using this technique it also mentions the Ayende method Karsten has linked to above. Once I get some time I should finish the rest of series off!</description>
		<content:encoded><![CDATA[<p>I posted about this topic a while back <a>http://journalofasoftwaredev.wordpress.com/2009/01/31/obstacles-of-unit-testing-methods-to-side-step-them-part-1-date-and-time/</a> using this technique it also mentions the Ayende method Karsten has linked to above. Once I get some time I should finish the rest of series off!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22787</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 21 Oct 2009 09:36:01 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22787</guid>
		<description>the performance cost that comes with this level of indirection will definitely not be noticable.  Even if you&#039;ve got iterations of millions, you won&#039;t notice this compared to _other_ performance penalties that you most likely will notice when dealing with that kind of volume.

or put differently: if you&#039;re dealing with millions of records and you notice a difference because of this trick, then i will very gladly tip my hat to you sir :)</description>
		<content:encoded><![CDATA[<p>the performance cost that comes with this level of indirection will definitely not be noticable.  Even if you&#8217;ve got iterations of millions, you won&#8217;t notice this compared to _other_ performance penalties that you most likely will notice when dealing with that kind of volume.</p>
<p>or put differently: if you&#8217;re dealing with millions of records and you notice a difference because of this trick, then i will very gladly tip my hat to you sir <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefano Ricciardi</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22786</link>
		<dc:creator>Stefano Ricciardi</dc:creator>
		<pubDate>Wed, 21 Oct 2009 09:20:03 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22786</guid>
		<description>This looks like a nice trick. Have you noticed any run-time penalties due to this level of indirection?

I am considering scenarios like bulking thousands (if not millions) of records where the the current time is used as a part of the key.</description>
		<content:encoded><![CDATA[<p>This looks like a nice trick. Have you noticed any run-time penalties due to this level of indirection?</p>
<p>I am considering scenarios like bulking thousands (if not millions) of records where the the current time is used as a part of the key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karsten</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22784</link>
		<dc:creator>Karsten</dc:creator>
		<pubDate>Wed, 21 Oct 2009 08:23:16 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22784</guid>
		<description>Ayende uses a variation of the same technique: http://ayende.com/Blog/archive/2008/07/07/Dealing-with-time-in-tests.aspx</description>
		<content:encoded><![CDATA[<p>Ayende uses a variation of the same technique: <a href="http://ayende.com/Blog/archive/2008/07/07/Dealing-with-time-in-tests.aspx" rel="nofollow">http://ayende.com/Blog/archive/2008/07/07/Dealing-with-time-in-tests.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #459</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22782</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #459</dc:creator>
		<pubDate>Wed, 21 Oct 2009 07:25:44 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22782</guid>
		<description>[...] Testability Of Date-Dependent Code - Davy Brion talks about two common techniques to enable the reliable testing of Date based code either by providing the date obtaining routine with a service which can be overridden for testing, or by routing all calls for dates through a custom static method which can be provided with dates to return [...]</description>
		<content:encoded><![CDATA[<p>[...] Testability Of Date-Dependent Code &#8211; Davy Brion talks about two common techniques to enable the reliable testing of Date based code either by providing the date obtaining routine with a service which can be overridden for testing, or by routing all calls for dates through a custom static method which can be provided with dates to return [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrey Titov</title>
		<link>http://davybrion.com/blog/2009/10/testability-of-date-dependent-code/comment-page-1/#comment-22781</link>
		<dc:creator>Andrey Titov</dc:creator>
		<pubDate>Wed, 21 Oct 2009 05:52:35 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1711#comment-22781</guid>
		<description>I&#039;ve seen a code that relies on two subsequent DateTime.Now calls returns the same value. I don&#039;t remember how it exactly looks, but it was something like this: 
if(IsPaidHour(DateTime.Now))
{
  price = GetCurrentPrice();
}
else 
{ 
  price = 0;
} 

and GetCurrentPrice() also calls DateTime.Now and throws if called in a wrong time. ;-)

So since that I count calls to DateTimeService.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve seen a code that relies on two subsequent DateTime.Now calls returns the same value. I don&#8217;t remember how it exactly looks, but it was something like this:<br />
if(IsPaidHour(DateTime.Now))<br />
{<br />
  price = GetCurrentPrice();<br />
}<br />
else<br />
{<br />
  price = 0;<br />
} </p>
<p>and GetCurrentPrice() also calls DateTime.Now and throws if called in a wrong time. <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>So since that I count calls to DateTimeService.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
