lundi 28 décembre 2015

How to write unit test for HttpContext.Current.Request.Headers

Below is an Example.

public class MyController : Controller
{
    [Route("~/api/mycontroller")]
    [HttpGet]
    public int ID()
    {
        try
        {
            return somecontroller.getID(ID);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

Above it the controller that is fetching the ID from the below controller. Below is the controller that it is inherited.

public class Controller : ApiController
{
    public int ID
    {
        get
        {
            return int.Parse(HttpContext.Current.Request.Headers["ID"]);
        }
    }
}

How do i write unit test case for the following.???

Aucun commentaire:

Enregistrer un commentaire