public async Task When_subRequirements_contain_another_OrRequirement__requirements_are_resolved_recursively()
        {
            var handlers = new List <IAuthorizationHandler>()
            {
                new PassThroughAuthorizationHandler()
            };
            var handler = new OrAuthorizationRequirementHandler(
                new OptionsWrapper <AuthorizationOptions>(new AuthorizationOptions()
            {
                InvokeHandlersAfterFailure = false
            }),
                new Lazy <IAuthorizationHandlerProvider>(new DefaultAuthorizationHandlerProvider(handlers)),
                new DefaultAuthorizationHandlerContextFactory());

            handlers.Add(handler);

            var requirement = new OrAuthorizationRequirement(new[] {
                new OrAuthorizationRequirement(new[] {
                    FailingRequirement,
                    FailingRequirement
                }),
                new OrAuthorizationRequirement(new[] {
                    FailingRequirement,
                    new OrAuthorizationRequirement(new[] {
                        FailingRequirement,
                        SucceedingRequirement
                    })
                })
            });
            var context = new AuthorizationHandlerContext(new[] { requirement }, BuildClaimsPrincipalWithClaims(), null);

            await handler.HandleAsync(context);

            Assert.True(context.HasSucceeded);
        }
        public async Task When_all_subRequirements_succeed__OrRequirement_succeeds()
        {
            var handler = new OrAuthorizationRequirementHandler(
                new OptionsWrapper <AuthorizationOptions>(new AuthorizationOptions()
            {
                InvokeHandlersAfterFailure = false
            }),
                new Lazy <IAuthorizationHandlerProvider>(new DefaultAuthorizationHandlerProvider(new[] { new PassThroughAuthorizationHandler() })),
                new DefaultAuthorizationHandlerContextFactory());
            var requirement = SucceedingRequirement.Or(SucceedingRequirement);
            var context     = new AuthorizationHandlerContext(new[] { requirement }, BuildClaimsPrincipalWithClaims(), null);

            await handler.HandleAsync(context);

            Assert.True(context.HasSucceeded);
        }
        public async Task When_first_subRequirement_succeeds__second_subRequirement_is_never_resolved()
        {
            bool secondRequirementEvaluated = false;
            var  handler = new OrAuthorizationRequirementHandler(
                new OptionsWrapper <AuthorizationOptions>(new AuthorizationOptions()
            {
                InvokeHandlersAfterFailure = false
            }),
                new Lazy <IAuthorizationHandlerProvider>(new DefaultAuthorizationHandlerProvider(new[] { new PassThroughAuthorizationHandler() })),
                new DefaultAuthorizationHandlerContextFactory());
            var requirement = SucceedingRequirement.Or(
                new AssertionRequirement(ctx => {
                secondRequirementEvaluated = true;
                return(true);
            }));
            var context = new AuthorizationHandlerContext(new[] { requirement }, BuildClaimsPrincipalWithClaims(), null);

            await handler.HandleAsync(context);

            Assert.True(context.HasSucceeded);
            Assert.False(secondRequirementEvaluated);
        }