title: How to write Unit test for Action that throw HttpException with StatusCode 404
body: <p>I have a below action in a controller which throw <strong>HttpException</strong> with status code <strong>404</strong>:</p>
  
  <pre><code>public async Task&lt;ActionResult&gt; Edit(int id)
  {
      Project proj = await _service.GetProjectById(id);
      if( proj == null)
      {
          throw new HttpException(404, "Project not found.");
      }
  }
  </code></pre>
  
  <p>To test this scenario, I have written below test case where I am catching AggregationException and rethrowing InnerException which is expected as HttpException:</p>
  
  <pre><code>[TestMethod]
  [ExpectedException(typeof(HttpException),"Project not found.")]
  public void Edit_Project_Load_InCorrect_Value()
  {
      Task&lt;ActionResult&gt; task = _projectController.Edit(3);
      try
      {
          ViewResult result = task.Result as ViewResult;
          Assert.AreEqual("NotFound", result.ViewName, "Incorrect Page title");
      }
      catch (AggregateException ex)
      {
          throw ex.InnerException;
      }
  }
  </code></pre>
  
  <p>This test run succefully and return ExpectedException.  I have two questions here:</p>
  
  <ol>
  <li>Is this right approach for writing unit test or there is more
  gracious way of testing it.</li>
  <li>Is this possible to check in Unit Test
  that user is getting correct error page( NotFound in this case).</li>
  </ol>