title: Mocking a property using SetupGet and SetupSet - this works, but why?
body: <p>Using Moq I am mocking a property, <code>Report TheReport { get; set; }</code> on an interface <code>ISessionData</code> so that I can inspect the value that gets set on this property.</p>
  
  <p>To achieve this I'm using <code>SetupGet</code> and <code>SetupSet</code> as follows:</p>
  
  <pre><code>// class-level fields
  protected Report _sessionReport;
  protected Mock&lt;ISessionData&gt; SessionData { get; private set; }
  </code></pre>
  
  <p>And in my setup method...</p>
  
  <pre><code>SessionData = new Mock&lt;ISessionData&gt;();
  
  SessionData
      .SetupSet(s =&gt; s.TheReport = It.IsAny&lt;Report&gt;())
      .Callback&lt;RDLDesigner.Common.Report&gt;(r =&gt;
      {
          _sessionReport = r;
          SessionData.SetupGet(s =&gt; s.TheReport).Returns(_sessionReport);
      });
  </code></pre>
  
  <p>I found this approach on <a href="https://stackoverflow.com/questions/1642631/moq-mocking-and-tracking-session-values/1643659#1643659">StackOverflow</a> and it works, but I do not understand why. I expected to have the call to <code>SetupGet</code> outside of the <code>SetupSet</code> callback.</p>
  
  <p>Can anyone explain how and why this approach works, and if it is the most appropriate way of mocking a property of this type?</p>
  
  <h2>Edit</h2>
  
  <p>Using <code>SessionData.SetupProperty(s =&gt; s.TheReport);</code> also works in my scenario, but I am still interested in any explanations for how and why my original approach worked.</p>