public void Validate_BodyIsNull()
        {
            AuthorisationCallbackDataValidator?validator = new AuthorisationCallbackDataValidator();

            AuthorisationCallbackData?data = new AuthorisationCallbackData(responseMode: "a", response: null);

            IList <ValidationFailure>?results = validator.Validate(data).Errors;

            results.Should().HaveCount(1);
        }
        public void Validate_BodyIsDefault()
        {
            AuthorisationCallbackDataValidator?validator = new AuthorisationCallbackDataValidator();

            AuthorisationCallbackData?data = new AuthorisationCallbackData(
                responseMode: "a",
                response: new AuthorisationCallbackPayload(authorisationCode: null, state: null));

            IList <ValidationFailure>?results = validator.Validate(data).Errors;

            results.Should().HaveCountGreaterThan(1);
        }
        public void Validate_BodyIsValid()
        {
            AuthorisationCallbackDataValidator?validator = new AuthorisationCallbackDataValidator();

            AuthorisationCallbackData?data = new AuthorisationCallbackData(
                responseMode: "a",
                response: new AuthorisationCallbackPayload(authorisationCode: "a", state: "a")
            {
                Id_Token = "a",
                Nonce    = null,
            });

            IList <ValidationFailure>?results = validator.Validate(data).Errors;

            results.Should().HaveCount(0);
        }
        public static async Task <AuthorisationCallbackDataFluentResponse> SubmitAsync(
            this AuthorisationCallbackDataContext context)
        {
            context.ArgNotNull(nameof(context));

            try
            {
                AuthorisationCallbackData authData = context.Data ?? new AuthorisationCallbackData(
                    responseMode: context.ResponseMode.ArgNotNullElseInvalidOp("ResponseMode not specified"),
                    response: context.Response.ArgNotNullElseInvalidOp("Response not specified"));

                IList <FluentResponseMessage> validationErrors = new AuthorisationCallbackDataValidator()
                                                                 .Validate(authData)
                                                                 .GetOpenBankingResponses();
                if (validationErrors.Count > 0)
                {
                    return(new AuthorisationCallbackDataFluentResponse(validationErrors));
                }

                RedirectCallbackHandler handler = new RedirectCallbackHandler(
                    apiClient: context.Context.ApiClient,
                    mapper: context.Context.EntityMapper,
                    openBankingClientRepo: context.Context.ClientProfileRepository,
                    domesticConsentRepo: context.Context.DomesticConsentRepository,
                    softwareStatementProfileService: context.Context.SoftwareStatementProfileService,
                    dbMultiEntityMethods: context.Context.DbContextService,
                    apiProfileRepo: context.Context.ApiProfileRepository);

                await handler.CreateAsync(authData);

                return(new AuthorisationCallbackDataFluentResponse(new List <FluentResponseMessage>()));
            }
            catch (AggregateException ex)
            {
                context.Context.Instrumentation.Exception(ex);

                return(new AuthorisationCallbackDataFluentResponse(ex.CreateErrorMessages()));
            }
            catch (Exception ex)
            {
                context.Context.Instrumentation.Exception(ex);

                return(new AuthorisationCallbackDataFluentResponse(new[] { ex.CreateErrorMessage() }));
            }
        }