title: XUnit, AutoFixture and Moq best practice
body: <p>I'm reading a lot of documentation and examples about how to properly unit test things combining the three components in the title. I came up with a test method for a method on my business logic, but it feels very clunky and dirty.</p>
  
  <p>I'd like to get some feedback from people more experienced on this topic to see how I can improve it.</p>
  
  <p>Here's the code, explanation follows:</p>
  
  <pre><code>[Fact]
  public void ShouldGetItemWithSameId()
  {
      var fixture = new Fixture().Customize(new AutoMoqCustomization());
      var facade = fixture.Freeze&lt;Mock&lt;IDataFacade&gt;&gt;();
      facade.Setup(c =&gt; c.Get(It.IsAny&lt;int&gt;())).Returns((int i) =&gt; new Item { Key = i });
  
      var sut = fixture.Create&lt;BusinessLogic&gt;();
      var expected = fixture.Create&lt;int&gt;();
  
      Assert.Equal(expected, sut.Get(expected).Key);
  }
  </code></pre>
  
  <p>My <code>BusinessLogic</code> class takes an <code>IDataFacade</code> as constructor parameter, which is responsible in its <code>Get(int)</code> method to retrieve the item with the same Id, pretty basic stuff.</p>
  
  <p>I freeze the <code>IDataFacade</code> mock and I set it up to construct an object matching the Id in <code>It.IsAny&lt;int&gt;</code>. I then create my SUT and test it. Works fine.</p>
  
  <p>I'd like to understand if I can improve things considering the following:</p>
  
  <ul>
  <li>I have to test more complex methods, like a <code>Query</code> method that takes a class containing a lot of properties that will be used as filters on matching properties on the type being queried. In this case I wouldn't know how to properly do the "Setup" part of the mock, since I have to initialize all, or close to all, the properties of the returned type, and in this scenario it's not a single Item but a whole collection</li>
  <li>The setup part feels out of place, I'd like to be able to reuse it in more methods</li>
  </ul>
  
  <p>I have some other tests using <code>Theory</code> with <code>AutoMoqData</code> but I was unable to achieve this test (and I think the more complex ones) using that approach, so I switched back to plain <code>Fact</code> with manually instantiated fixture.</p>
  
  <p>Any help will be extremely appreciated.</p>