title: Getting list of objects in an OkResult
body: <p>I'm trying to unit test my web services using Moq, and I have the following test:</p>
  
  <pre><code>[TestMethod()]
  public void GetCoursesTest()
  {
      var response = _coursesController.GetCourses();
      var contentResult = response as OkNegotiatedContentResult&lt;List&lt;Course&gt;&gt;;
      Assert.AreEqual(contentResult.Content.Count(), _educationCoursesData.Count);
  }
  </code></pre>
  
  <p>Here, <code>GetCourses()</code> is:</p>
  
  <pre><code>public IHttpActionResult GetCourses() 
  {
      try
      {
          return Ok(_entities.Courses.ToList().Select(course =&gt; new CourseDTO
          {
              Id = course.Id,
              CrsName = course.CrsName,
              CrsHour = course.CrsHour,
              CrsDay = course.CrsDay,
              CrsMin = course.CrsMin,
              Teacher = course.Teacher
          }));
      }
      catch
      {
          return InternalServerError();
      }
  }
  </code></pre>
  
  <p>So its result is a list of obejcts. However, when I try to grab the list of these objects into <code>contentResult</code> via <code>response as OkNegotiatedContentResult&lt;List&lt;Course&gt;&gt;;</code>, <code>contentResult</code> is just a <code>null</code>. How can I read the list of objects from the OkResult into a variable that I can do <code>Count()</code> on?</p>