public void PassIsFalse() { var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/api/values/get?pass=false"); var controllerContext = ContextUtil.CreateControllerContext(request: request); var actionContext = ContextUtil.CreateActionContext(controllerContext: controllerContext); var expected = HttpStatusCode.Unauthorized; var target = new MyAuthorizationFilter() as IAuthorizationFilter; var actual = target.ExecuteAuthorizationFilterAsync(actionContext, CancellationToken.None, () => { return new TaskCompletionSource<HttpResponseMessage>().Task; }).Result; Assert.AreEqual(expected, actual.StatusCode); }
public void WithoutPass() { var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/api/values/get"); var controllerContext = ContextUtil.CreateControllerContext(request: request); var actionContext = ContextUtil.CreateActionContext(controllerContext: controllerContext); var expected = new HttpResponseMessage(HttpStatusCode.OK); var target = new MyAuthorizationFilter() as IAuthorizationFilter; var actual = target.ExecuteAuthorizationFilterAsync(actionContext, CancellationToken.None, () => { var source = new TaskCompletionSource<HttpResponseMessage>(); source.SetResult(expected); return source.Task; }).Result; Assert.AreSame(expected, actual); }