public void DeletePayment() { // Arrange paymentRepository.Setup(x => x.GetPaymentById(1)).Returns(getPayment); paymentRepository.Setup(c => c.DeleteObject(It.IsAny <Payment>(), It.IsAny <bool>())).Returns(true); var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { { "controller", "payment" } }); var controller = new PaymentController(paymentRepository.Object) { Request = new HttpRequestMessage(HttpMethod.Delete, "http://localhost:1175/api/Payment/DeletePayment/{paymentId}") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.DeletePaymentById(1); // Assert Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); }