Beispiel #1
0
        public void Authen_Admin_Test()
        {
            FilterContext        filterContext = null; // new Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext(null, null, null);
            ExecuteContextAuthen authen        = new ExecuteContextAuthen(filterContext, new AdminUser());

            Assert.IsTrue(authen.Authen(new DefaultParceAuthenTypeAccordParameterName()) == EnumAuthenResult.Authened, "管理员肯定有权限");
        }
Beispiel #2
0
        public void Authen_Withuserqueryprivilege_Test()
        {
            ControllerActionDescriptor controllerActionDescriptor = new ControllerActionDescriptor();

            controllerActionDescriptor.MethodInfo = this.GetType().GetMethod(nameof(QueryUser), BindingFlags.Public | BindingFlags.Instance);

            var actionContext = new ActionContext();

            actionContext.ActionDescriptor = controllerActionDescriptor;
            actionContext.HttpContext      = new Mock <HttpContext>().Object;
            actionContext.RouteData        = new RouteData();
            var filterContext = new ExceptionContext(actionContext, new List <IFilterMetadata>());

            var authen = new ExecuteContextAuthen(filterContext, new UserWithUserQueryPrivilege());

            Assert.IsTrue(authen.Authen(new DefaultParceAuthenTypeAccordParameterName()) == EnumAuthenResult.Authened, "有用户查询权限的人访问 QueryUser 时允许访问");
        }