title: How to access JsonResult data when testing in ASP.NET MVC
body: <p>I have this code in C# mvc Controller:    </p>
  
  <pre><code>[HttpPost]
      public ActionResult Delete(string runId)
      {
          if (runId == "" || runId == null)
          {
              return this.Json(new { error = "Null or empty params" });
          }
          try
          {
              int userId = (int)Session["UserId"];
              int run = Convert.ToInt32(runId);
  
              CloudMgr cloud = new CloudMgr(Session);
              cloud.DeleteRun(userId, run);
  
              return this.Json(new { success = true });
          }
          catch (Exception ex)
          {
              return this.Json(new { error = ex.ToString() });
          }
      }
  </code></pre>
  
  <p>How I can access my Json "error" field in a ControllerTest to check if it is null or not? </p>
  
  <pre><code>[TestMethod]
      public void DeleteWrongParam()
      {
          WhatIfController controller = new WhatIfController();
          controller.ControllerContext = 
          TestUtils.CreateMockSessionControllerContext().Object as ControllerContext;
  
          JsonResult result = controller.DeleteWhatIf(null) as JsonResult;
  </code></pre>
  
  <p><code>Assert.IsNotNull(result.Data.error);</code> is what I would like to do. Any Ideas? Thanks.</p>