Unit test ASP.NET Web Api attrubute routing

by sunil ravulapalli /13. November 2013 03:50 /asp.net-web-api /Comments (0)

Most of the stuff is standard expect you need to call config.EnsureInitialized() after WebApiConfig.Register(config)

            //Arrange            
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost.com/api/v1/account/12345678/info");
            var config = new HttpConfiguration();

            //Act
            WebApiConfig.Register(config);
            config.EnsureInitialized();
            var route = WebApi.RouteRequest(config, request);

            //Assert
            Assert.AreEqual("InfoController", route.Controller.Name);
            Assert.AreEqual("Get", route.Action);
blog comments powered by Disqus