title: Error Setting up Property During Unit Testing Using Moq
body: <p>Alright, let's assume I have a class like the following ...</p>
  
  <pre><code>public class Foo : IFoo
  {
      public string Bar
      {
          get { ... }
      }
  
      public void Initialize()
      {
          ...
      }
  }
  </code></pre>
  
  <p>... and as you can see it implements an interface so I can mock it. Now, in my unit test I'm building the mock like this ...</p>
  
  <pre><code>var mock = new Mock&lt;IFoo&gt;();
  mock.SetupProperty(p =&gt; p.Bar).SetReturnsDefault("Some static value here.");
  </code></pre>
  
  <p>... however, when the test runs I get the following error ...</p>
  
  <blockquote>
    <p>System.ArgumentException: Property IFoo.Bar is read-only.
    Parameter name: expression</p>
  </blockquote>
  
  <p>So, three questions:</p>
  
  <ol>
  <li>What am I doing wrong?</li>
  <li>What do I need to do?</li>
  <li>Can you please explain how I misunderstood <code>SetReturnsDefault</code>?</li>
  </ol>
  
  <p>Thanks all!</p>