title: Is it possible to set a property with no setter using Moq?
body: <p>Im doing some research. I want to use moq and pass it to an MVC controller so allow it to set some values in session. I have written some code to see if its possible to 'open up' a property with no setter. Just don't know if its possible...</p>
  
  <p>The following code was my attempt at trying to set a property witn no setter!</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Moq;
  
  namespace TestMoq
  {
      class Program
      {
          static void Main(string[] args)
          {
              var mock = new Mock&lt;TestClass&gt;();
  
              mock.SetupProperty(f =&gt; f.VarWithNoSetter);
  
              mock.Object.VarWithNoSetter = "Set";
  
              Console.WriteLine(mock.Object.VarWithNoSetter);
  
              Console.ReadLine();
          }
      }
  
      public class TestClass
      {
          private string _varWithNoSetter;
          public string VarWithNoSetter
          {
              get { return _varWithNoSetter; }
          }
  
          public TestClass()
          {
          }
      }
  }
  </code></pre>