Re: Url.Route method throwing exception

You haven't set the controller context on your controller and hence the NullReferenceException. webapi initializes the ControllerContext property on your controller with the right value (request, controllerdescriptor and HttpConfiguration). If you are trying
to test that then you need to set the context yourself.

may be something like

contactsController.ControllerContext = new HttpControllerContext(new HttpConfiguration(), new HttpRouteData(new HttpRoute("DummyRoute")), new HttpRequestMessage("http://localhost/api/contacts/1"));

Note: Web host abstract the usage of RouteCollection class using HttpRouteCollection class. Although, the self host does not use RouteCollection class but the behaviour is same(AFAIK). See this for
detail.