Testing

Testing of controllers are easy thanks to the ControllerTester class.

void MyTest()
{
    // Create a controller.
    MyController controller = new MyController();

    // build up a form that is used by the controller.
    HttpForm form = new HttpForm();
    form.Add("user[firstName]", "Jonas");

    // Invoke the request
    ControllerTester tester = new ControllerTester();
    IHttpResponse response;
    string text = tester.Post(controller, "/user/create/", form, out response, null);

    // validate response back from controller.
    Assert.Equal("User 'Jonas' has been created.", text);
}

Last edited Sep 1, 2008 at 3:38 PM by jgauffin, version 1

Comments

No comments yet.