title: Setup a Mocked (Moq) class that only exposes properties
body: <p>I am trying to mock (using Moq) a class set a return object on a class that only exposes two properties.</p>
  
  <p>In my limited Moq experience I would normally use a Setup() lamda to define the method call and then Returns() to spit back the desired output.</p>
  
  <p>What I am falling down on here is the Setup(). There isn't a "method" to call as the constructor does the work, populates the two properties and then returns.</p>
  
  <p>My class that I want to mock...obviously dummied down:</p>
  
  <pre><code>public class CarResponse
  {
      public IMetaModel meta { get; set; }
      public List&lt;ICarModel&gt; cars { get; set; }
  
      public CarResponse(Common.Models.Car car)
      {
          this.cars = new List&lt;ICarModel&gt;();
      }
  }
  </code></pre>
  
  <p>My feeble attempt at mocking:</p>
  
  <pre><code>private Mock&lt;CarResponse&gt; _carResponse = new Mock&lt;CarResponse&gt;(MockBehavior.Strict);
  _carResponse.Setup( ????? ).Returns(new CarResponse() { meta = new MetaModelV2(), cars = foo });
  </code></pre>
  
  <hr>
  
  <p>To further clarify...here is the code I am trying to write a unit test for:</p>
  
  <pre><code>public HttpResponseMessage AddPickup()
  {
       //....code removed for brevity....
  
      //this repository is mocked and returns the object exactly as I want it
       var car = carRepository.GetCar(carId);
  
     if (!errorInfo.Any()) //This check is bogus it never gets sets
     {
       RequestHelper rqh = new RequestHelper();
  
       response = rqh.CreateResponse(Request, HttpStatusCode.OK, new CarResponse(car));
  }
  </code></pre>
  
  <p>My unit test:</p>
  
  <pre><code>[TestMethod]
  public void AddValidPickupCorrectResponse()
  {
     //arrange
     //...lots of code here left off for setting up http context etc
  
    //act---
    var response = controller.AddPickup();
  
    //assert
  
  }
  </code></pre>
  
  <p>If I were to use a precanned object as suggested how would I "hook" it to the code under test. For example I write a unit test that uses my pre-canned object instead of a Moq but how do I get that pre-canned object to be used by the SUT?</p>