//[ExpectedException(typeof(Exception))] public void TestGetServices() { var allServices = new[] { new Service() { ServiceId = "1", Name = "Service1", Building = "1" }, new Service() { ServiceId = "2", Name = "Service2", Building = "1" }, }; var mockServiceValidator = new Mock <IServiceValidator>(); mockServiceValidator.Setup(x => x.GetServices()).Returns(allServices); var controller = new ServicesController(mockServiceValidator.Object); // Arrange var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("TODO_PAGOS_TOKEN", "1"); // Don't forget these lines, if you do then the request will be null. controllerContext.Request = request; controller.ControllerContext = controllerContext; IHttpActionResult actionResult = controller.GetServices(); //throw new Exception(actionResult.GetType().ToString()); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Service> >; Assert.IsNotNull(contentResult); }