public async Task HandleRequest_GivenThatMediatorExecutionIsForbidden_ReturnsForbiddenResponse()
        {
            // Arrange
            var request = this.fixture.Create <TestRequest>();

            this.mediator.Execute <TestRequest, OperationResult>(request)
            .Returns(OperationResultCreator.Forbidden());

            // Act
            var response = await this.sut.TestHandleResuest <TestRequest, OperationResult>(request);

            // Assert
            Assert.IsType <ForbidResult>(response);
        }
        public async Task <OperationResult> Execute(TRequest request)
        {
            var requestName = typeof(TRequest).Name;

            if (this.interactor == null)
            {
                throw new InvalidOperationException($"There is no interactor for [{requestName}]");
            }

            if (this.authorizer == null && interactor.HasAuthorizer)
            {
                throw new InvalidOperationException($"There is no authorizer for [{requestName}]");
            }

            if (this.validator == null && interactor.HasValidator)
            {
                throw new InvalidOperationException($"There is no validator for [{requestName}]");
            }

            if (interactor.HasAuthorizer)
            {
                logger.LogInformation($"Authorizing [{requestName}]");

                var authorizationResult = await this.authorizer.Authorize(request);

                if (!authorizationResult.Succeeded)
                {
                    return(OperationResultCreator.Forbidden(authorizationResult.Errors));
                }
            }

            if (interactor.HasValidator)
            {
                logger.LogInformation($"Validating [{requestName}]");

                var validationResult = await this.validator.Validate(request);

                if (!validationResult.Succeeded)
                {
                    return(validationResult);
                }
            }

            logger.LogInformation($"Handling [{requestName}]");
            return(await this.interactor.Handle(request));
        }