title: How to test a web api post method which receives a class
body: <p>I have created an ASP.NET web API which has a controller named <code>ImageSaveController</code>. This has an <code>InsertImage</code> method which inserts data into database and is an <code>HttpPost</code> method. This method receives an object of type <code>ImageData</code> as a parameter. The code for the controller and the parameter class are given below:</p>
  
  <pre><code>public class ImageSaveController : ApiController
  {
      [HttpPost]
      public IHttpActionResult InsertImage(ImageData imageData)
      {
          System.Data.SqlClient.SqlConnection conn = null;
          try
          {               
              //Image save to database code here
          }
          catch (Exception ex)
          {
              return Content(HttpStatusCode.NotModified, ex.Message);
          }
          finally
          {
              if (conn != null)
                  conn.Close();
          }
          return Content(HttpStatusCode.OK,""); 
      }
  }
  
  //ImageData class
  public class ImageData
  {
      public int Id { get; set; }
      public byte[] ImageValue { get; set; }
  }
  </code></pre>
  
  <p>I would like to test it from a client. As you can notice, the <code>ImageValue</code> property of the <code>ImageData</code> class is a <code>byte</code> array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as <code>json</code> and I am not sure how to construct the <code>json</code> for this purpose. I am also not sure whether it could be tested using the chrome app called postman.</p>