public void GetFriendById() { // Arrange friendRepository.Setup(x => x.GetFriendById(1)).Returns(getFriend); var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { { "controller", "friend" } }); var controller = new FriendController(friendRepository.Object) { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:1175/api/Friend/FriendId?friendId={friendId}") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.GetFriendById(1); // Assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }