public async Task Handle_RequestにするAuthorizerが空の場合はなにも実行されない()
    {
        var list    = new List <string>();
        var factory = new ServiceFactory(type =>
        {
            return(Enumerable.Empty <IAuthorizer <TestBehaviorRequest> >());
        });
        var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory);
        await auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse()));

        list.Should().BeEmpty();
    }
    public async Task Handle_Requestに一致する全てのAuthorizerが実行される()
    {
        var list    = new List <string>();
        var factory = new ServiceFactory(type =>
        {
            return(new IAuthorizer <TestBehaviorRequest>[]
            {
                new SuccessAuthorizer1(list),
                new SuccessAuthorizer2(list)
            });
        });
        var auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory);
        await auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse()));

        list.Count.Should().Be(2);
        list[0].Should().Be(AuthorizerMessages.SuccessAuthorizer1Message);
        list[1].Should().Be(AuthorizerMessages.SuccessAuthorizer2Message);
    }
    public async Task Handle_失敗した時にメッセージが設定されていない場合は例外にデフォルトのメッセージが設定される()
    {
        using var cal = TestHelper.SetEnglishCulture();
        var list    = new List <string>();
        var factory = new ServiceFactory(type =>
        {
            return(new IAuthorizer <TestBehaviorRequest>[]
            {
                new FailurAuthorizer1(list, string.Empty),
            });
        });
        var         auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory);
        Func <Task> act  = () => auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse()));

        await act.Should().ThrowAsync <UnauthorizedException>().WithMessage("Not authorized.");

        list.Count.Should().Be(1);
        list[0].Should().Be(AuthorizerMessages.FailurAuthorizer1Message);
    }
    public async Task Handle_Authorizerが途中で失敗した場合はそこで処理が止まりUnauthorizedExceptionが発行される()
    {
        var list    = new List <string>();
        var factory = new ServiceFactory(type =>
        {
            return(new IAuthorizer <TestBehaviorRequest>[]
            {
                new SuccessAuthorizer1(list),
                new FailurAuthorizer1(list, "unauthorized!"),
                new SuccessAuthorizer2(list)
            });
        });
        var         auth = new AuthorizationBehavior <TestBehaviorRequest, TestBehaviorResponse>(factory);
        Func <Task> act  = () => auth.Handle(new TestBehaviorRequest(), new CancellationToken(), () => Task.FromResult(new TestBehaviorResponse()));

        await act.Should().ThrowAsync <UnauthorizedException>().WithMessage("unauthorized!");

        list.Count.Should().Be(2);
        list[0].Should().Be(AuthorizerMessages.SuccessAuthorizer1Message);
        list[1].Should().Be(AuthorizerMessages.FailurAuthorizer1Message);
    }