title: Unit test failing only when run on the build server
body: <p>To aid unit-testing we have wrapped up the <code>DateTime</code> class in a delegate so that <code>DateTime.Now</code> can be overridden in a unit-test. </p>
  
  <pre><code>public static class SystemTime
  {
      #region Static Fields
  
      public static Func&lt;DateTime&gt; Now = () =&gt; DateTime.Now;
  
      #endregion
  }
  </code></pre>
  
  <p>Here is an example of its use in an xunit unit-test:</p>
  
  <pre><code>[Fact]
  public void it_should_update_the_last_accessed_timestamp_on_an_entry()
  {
      // Arrange
      var service = this.CreateClassUnderTest();
  
      var expectedTimestamp = SystemTime.Now();
      SystemTime.Now = () =&gt; expectedTimestamp;
  
      // Act
      service.UpdateLastAccessedTimestamp(this._testEntry); 
  
      // Assert
      Assert.Equal(expectedTimestamp, this._testEntry.LastAccessedOn);
  }   
  </code></pre>
  
  <p>The test runs fine locally, however it is failing on our build server as the datetimes differ in the <code>Assert</code> statement. </p>
  
  <p>I'm struggling to think of a reason why it would fail given that the <code>DateTime</code> is mocked via the above mentioned delegate wrapper. I've verified there are no issues in the implementation of the <code>UpdateLastAccessedTimestamp</code> method and that the test passes when run locally.</p>
  
  <p>Unfortunately I can't debug it on our build server. Any ideas why it would fail only when run on the build server? </p>
  
  <p>Note that the implementation of <code>UpdateLastAccessedTimestamp</code> is as follows: </p>
  
  <pre><code>public void UpdateLastAccessedTimestamp(Entry entry)
  {
      entry.LastAccessedOn = SystemTime.Now();
      this._unitOfWork.Entries.Update(entry);
      this._unitOfWork.Save();
  }
  </code></pre>
  
  <p>The <code>Entry</code> class is just a simple POCO class that has a number of fields including the <code>LastAccessedOn</code> field:</p>
  
  <pre><code>public class Entry
  {
     public DateTime LastAccessedOn { get; set; }
  
     //other fields that have left out to keep the example concise
  }
  </code></pre>