title: How do I initialize complex properties with no setter using Moq?
body: <h2>Problem:</h2>
  
  <p>I'm having trouble mocking two properties of my Form using the Moq framework.  There are examples of how to do what I'm trying to do out there, but they are all with properties whose type is simple, like <code>string</code> or <code>int</code>.</p>
  
  <p>The <code>Fields</code> property of <code>IMainForm</code> are not being initialized like they do for <code>MainForm</code>, which makes sense to me why (interfaces do not allow this type of initialize to happen).  I just don't know how to overcome it.</p>
  
  <p>I have a form defined something like this:</p>
  
  <pre><code>public partial class MainForm : XtraForm, IMainForm
  {
      ...
  
      #region Public Properties
  
      public RichEditDocumentServer DocServer { get; } = new RichEditDocumentServer();
  
      public Dictionary&lt;string, string&gt; Fields { get; } = new Dictionary&lt;string, string&gt;();
  
      #endregion
  
      ...
  }
  </code></pre>
  
  <p>In my tests, my fixture's setup is as follows:</p>
  
  <pre><code>...
  #region Private Variables
  
  private Mock&lt;IConnector&gt; _arc = new Mock&lt;IConnector&gt;();
  private Mock&lt;IMainForm&gt; _arForm = new Mock&lt;IMainForm&gt;();
  private MainController _controller;
  
  #endregion
  
  [TestFixtureSetUp]
  public void FixtureSetup()
  {
      _arc.SetupAllProperties();
      _arForm.SetupAllProperties();
      _controller = new MainController(_arc.Object)
      {
          View = _arForm.Object
      };
  }
  ...
  </code></pre>
  
  <h2>The line that fails in my test (but passes when I run with a UI):</h2>
  
  <pre><code>View.Fields.Add(...) // throws NullReferenceException because Fields in null
  </code></pre>
  
  <h2>Intention:</h2>
  
  <p>I don't want the public interface to my forms allowing the <code>Fields</code> or <code>DocServer</code> properties to be set to something other than what they are initially set to.  But this still allows <code>.Add(...)</code> to be called on the <code>Fields</code> property for instance.  I intend to test that adding <code>KeyValuePair</code>s to the <code>Fields</code> is a successful step in making more business-logic-y type stuff to happen.</p>
  
  <h2>Question:</h2>
  
  <p>What is the <strong>Moq</strong> way of initializing complex properties with no setter?  My tests fail because these properties are <code>null</code>.  Thank you.</p>