mercredi 25 novembre 2015

Unit Testing Contollers with http request

In c#, i do have a method in my controller which gets content from request object.

public class xController: BaseController
{
    [HttpPost]
    [Route("confirm")]
    public void Confirmation(string Content)
    {
        var content = Request.Content.ReadAsStringAsync().Result;
    }

}

I build a unit test with following code but getting error with null ref for request object.

[Test]
public void Confirmation()
{
   //arrange
   var con = new xController();

   //act
   var res = con.Confirmation("hello");

   //assert
   Assert.IsNotNull(res);
}

Aucun commentaire:

Enregistrer un commentaire