title: Unit Test Throwing "System.NullReferenceException", using Moq and Nunit
body: <p>I am newbie to moq and unit testing. So, I don't understand it thoroughly. pardon me if question is stupid. please help me understand the following scenario. </p>
  
  <p>Following is my simple test</p>
  
  <pre><code>[Test]
  public void TryMoq() {
      var mock = new Mock&lt;IDummyInterface&gt;();
      var dummy = new DummyClass(mock.Object);
      mock.VerifySet(m =&gt; m.Model = It.Is&lt;DummyModel&gt;(mo =&gt; mo.MyProperty == "foo"));
  }
  </code></pre>
  
  <p>and the code that I m trying to test</p>
  
  <pre><code>public class DummyClass
  {
      public DummyClass(IDummyInterface i) {
          i.Model = new DummyModel() ;
          i.Model.MyProperty = "foo";
  
      }
  }
  
  public class DummyModel
  {
      public string MyProperty { get; set; }
  }
  
  public interface IDummyInterface {
       DummyModel Model { get; set; }
  }
  </code></pre>
  
  <p>now at line "i.Model.MyProperty = "foo";" "System.NullReferenceException" is being thrown. </p>
  
  <p>Why, I think the reason in since I m using Moq. </p>
  
  <p>strange thing is that if i change the constructor of the "DummyClass". Like this </p>
  
  <pre><code>public DummyClass(IDummyInterface i)
      {
          i.Model = new DummyModel() { MyProperty ="foo"};
          //i.Model.MyProperty = "foo";
  
      }
  </code></pre>
  
  <p>Test Passes . In the second case even if I try changing the value of "foo" to "bar". Test Fails.(This is good though).</p>
  
  <p>I just want to understand whats going on. and how am I suppose to moq and verify child properties. </p>