title: How to test JsonResult from .NET MVC controller
body: <p>The controller action being tested: </p>
  
  <pre><code>    [AuthorizeUser]
      [HttpPost]
      [ValidateJsonAntiForgeryToken]
      public ActionResult EventDetails(int eventId)
      {
          string details = this._eventDataProvider.GetById(eventId).Comments;
  
          if (string.IsNullOrEmpty(details))
              details = "This location has not entered any comments or further details for this event.";
  
          return Json(new
          {
              details = details
          });
      }
  </code></pre>
  
  <p>Test code for the controller: wondering what I need to do to test the Json being returned from the controller:</p>
  
  <pre><code>    [TestMethod]
      public void DetailsAreReturned()
      {
          // Arrange
          eventsController = new EventsController(eventDataProvider.Object, playerEventDataProvider.Object, userDataProvider.Object,
                                                  tokenAuthent.Object, dataContext.Object, customerLocationDataProvider.Object);
  
          eventDataProvider.Setup(x =&gt; x.GetById(1)).Returns(new Event() { Comments = "test" });
  
          // Act
          JsonResult result = (JsonResult) eventsController.EventDetails(1);
  
          // Assert
          Assert.IsNotNull(result.Data);
  
          Assert.AreEqual(??, result);
      }
  </code></pre>