title: Moq mock generic class
body: <p>Having the following in my code:</p>
  
  <pre><code>var contact = m_someFactory.Create&lt;IContact&gt;(contact, Page.ID);
  </code></pre>
  
  <p>code from Factory:</p>
  
  <p>ObjectFactory implements AbstractFactory</p>
  
  <pre><code>    ObjectsFactory : AbstractFactory
  {
      public T Create&lt;T&gt;()
      {
          var factory = this as IInsertFactoryMethod&lt;T&gt;;
          return factory != null
              ? factory.Create()
              : default(T);
      }
  </code></pre>
  
  <p>I want to be able to mock this.
  I've created a class that implements IContact</p>
  
  <pre><code>public class Contact{
        public Name {get; set;}  
        IOrganization Organization { get; set; }
  }
  </code></pre>
  
  <p>For setup I tried this:</p>
  
  <pre><code>FactoryMock = new Mock&lt;ObjectsFactory&gt;();
  FactoryMock.Setup(x =&gt; x.Create&lt;IContact&gt;()).Returns(new Mock&lt;IContact&gt;().Object);
  </code></pre>
  
  <p>and this</p>
  
  <pre><code>FactoryMock.Setup(x =&gt; x.Create&lt;IContact&gt;(null, It.IsAny&lt;int&gt;())).Returns(new Mock&lt;IContact&gt;().Object);
  </code></pre>
  
  <p>During the setup I get the following:</p>
  
  <blockquote>
    <p>Additional information: Invalid setup on a non-virtual (overridable in
    VB) member: x => x.Create()</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p>UPDATE:
  In my code I have the following:</p>
  
  <pre><code>    var contact = m_someFactory.Create&lt;IContact&gt;(contact, Page.ID);
  var organization = contact.Organization;
  </code></pre>
  
  <p>How would I set this up if Organization is an interface in Contact?</p>