public void Initialize() { filter = new GlobalExceptionAttribute(); var configuration = new HttpConfiguration(); var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "mywebapi/test"); httpRequestMessage.Content = new StringContent("", Encoding.UTF8, "application/x-www-form-urlencoded"); httpRequestMessage.RequestUri = new Uri("http://localhost:8080/addlog/test"); httpRequestMessage.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; string controllerName = "UsersController"; Type controllerType = typeof(BaseApiController); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.Conflict, Content = new StringContent("test") }; httpActionExecutedContext = new HttpActionExecutedContext { ActionContext = new HttpActionContext { ActionDescriptor = new Mock <HttpActionDescriptor>() { CallBase = true }.Object, ControllerContext = new HttpControllerContext { Configuration = new HttpConfiguration(new HttpRouteCollection("api")), Request = httpRequestMessage, RequestContext = new HttpRequestContext(), ControllerDescriptor = new HttpControllerDescriptor(configuration, controllerName, controllerType) }, Response = response, }, Response = response }; }
public void GlobalExceptionAttribute_AllowMultipleTest() { GlobalExceptionAttribute actionFilter = new GlobalExceptionAttribute(); Assert.IsTrue(actionFilter.AllowMultiple); }