title: How do I mock a private field?
body: <p>I'm really new to mocks and am trying to replace a private field with a mock object. Currently the instance of the private field is created in the constructor. My code looks like...</p>
  
  <pre><code>public class Cache {
      private ISnapshot _lastest_snapshot;
  
      public ISnapshot LatestSnapshot {
          get { return this._lastest_snapshot; }
          private set { this._latest_snapshot = value; }
      }
  
      public Cache() {
          this.LatestSnapshot = new Snapshot();
      }
  
      public void Freeze(IUpdates Updates) {
          ISnapshot _next = this.LastestSnapshot.CreateNext();
          _next.FreezeFrom(Updates);
          this.LastestSnapshot = _next;
      }
  
  }
  </code></pre>
  
  <p>What I'm trying to do is create a unit test that asserts <code>ISnapshot.FreezeFrom(IUpdates)</code> is called from within <code>Cache.Freeze(IUpdates)</code>. I'm guessing I should replace the private field <code>_latest_snapshot</code> with a mock object (maybe wrong assumption?). How would I go about that while still retaining a parameterless constructor and not resorting to making <code>LatestSnapshot</code>'s set public?</p>
  
  <p>If I'm totally going about writing the test the wrong way then please do point out as well.</p>
  
  <p>The actual implementation of <code>ISnapshot.FreezeFrom</code> itself calls a heirarchy of other methods with a deep object graph so I'm not too keen on asserting the object graph.</p>
  
  <p>Thanks in advance.</p>