コード例 #1
0
        public async Task Given_request_meets_policy_then_request_succeeds(
            Mock <IAuthorizationService> authorizationService,
            Mock <IHttpContextAccessor> httpContextAccessor,
            string policyName,
            Request request)
        {
            authorizationService.Setup(a => a.AuthorizeAsync(
                                           It.IsAny <ClaimsPrincipal>(),
                                           It.IsAny <object>(),
                                           policyName))
            .ReturnsAsync(AuthorizationResult.Success);

            var pipeline = new AuthorizationPipeline <Request, Response>(
                authorizationService.Object,
                httpContextAccessor.Object,
                policyName);

            Func <Task <Response> > test = () => pipeline.Handle(request, default, Next);
        public async Task Given_request_meets_policy_then_request_succeeds(
            Mock <IAuthorizationService> authorizationService,
            Mock <IHttpContextAccessor> httpContextAccessor,
            Request request)
        {
            var policy = new AuthorizationPolicy(
                new List <IAuthorizationRequirement>()
            {
                new DummyRequirement()
            },
                new List <string>());

            authorizationService.Setup(a => a.AuthorizeAsync(
                                           It.IsAny <ClaimsPrincipal>(),
                                           It.IsAny <object>(),
                                           It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .ReturnsAsync(AuthorizationResult.Success);

            var pipeline = new AuthorizationPipeline <Request, Response>(
                authorizationService.Object,
                httpContextAccessor.Object,
                policy);

            Func <Task <Response> > test = () => pipeline.Handle(request, default, Next);