예제 #1
0
        public void SmokeTestQueryGraphQLWithVariables_isSuccessful()
        {
            BraintreeGraphQLService service = GetService();

            var definition = @"
mutation CreateClientToken($input: CreateClientTokenInput!) {
    createClientToken(input: $input) {
        clientMutationId
        clientToken
    }
}";
            var variables  = new Dictionary <string, object> {
                { "input", new Dictionary <string, object> {
                      { "clientMutationId", "abc123" },
                      { "clientToken", new Dictionary <string, object> {
                            { "merchantAccountId", "ABC123" }
                        } }
                  } }
            };

            var result = service.QueryGraphQL(definition, variables);

            Assert.IsNull(result.errors);
            var createClientToken = (Dictionary <string, object>)result.data["createClientToken"];
            var clientToken       = createClientToken["clientToken"];

            Assert.IsInstanceOf <string>(clientToken);
        }
예제 #2
0
        public void SmokeTestQueryGraphQLWithoutVariables_isSuccessful()
        {
            BraintreeGraphQLService service = GetService();

            var result = service.QueryGraphQL("query {\n    ping\n}", null);

            Assert.AreEqual(result.data["ping"], "pong");
        }
예제 #3
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorExceptionIsNull_throwsUnexpectedException()
        {
            GraphQLError    error    = new GraphQLError();
            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(new GraphQLError());

            Assert.Throws <UnexpectedException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #4
0
        public void SmokeTestQueryGraphQLWithoutVariablesInProduction_canMakeRequestsWithoutSSLErrors()
        {
            Configuration configuration = new Configuration(
                Environment.PRODUCTION,
                "merchant_id",
                "public_key",
                "private_key"
                );
            BraintreeGraphQLService service = new BraintreeGraphQLService(configuration);

            // we get an expected authentication error here
            // the important thing is that we don't get an ssl error
            Assert.Throws <AuthenticationException>(() => service.QueryGraphQL("query {\n    ping\n}", null));
        }
예제 #5
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsUnsupportedClient_throwsUnsupportedClientException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "UNSUPPORTED_CLIENT");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <UpgradeRequiredException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #6
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsNotFound_throwsNotFoundException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "NOT_FOUND");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <NotFoundException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #7
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsAuthorization_throwsAuthorizationException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "AUTHORIZATION");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <AuthorizationException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #8
0
        public void DoNotThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsValidation()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "VALIDATION");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response);
        }
예제 #9
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsUnknown_throwsUnexpectedException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "UNKNOWN");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <UnexpectedException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #10
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsBraintreeServiceAvailability_throwsDownForMaintanceException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "SERVICE_AVAILABILITY");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <DownForMaintenanceException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #11
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsInternal_throwsServerException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "INTERNAL");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <ServerException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #12
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsResourceLimit_throwsTooManyRequestsException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "RESOURCE_LIMIT");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <TooManyRequestsException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
예제 #13
0
        public void SmokeTestQueryGraphQLWithVariables_isUnsuccessful_andReturnsParsableErrors()
        {
            BraintreeGraphQLService service = GetService();

            var definition = @"
query TransactionLevelFeeReport($date: Date!, $merchantAccountId: ID) {
    report {
        transactionLevelFees(date: $date, merchantAccountId: $merchantAccountId) {
            url
        }
    }
}";
            var variables  = new Dictionary <string, object> {
                { "date", "2018-01-01" },
                { "merchantAccountId", "some_merchant" }
            };

            var result = service.QueryGraphQL(definition, variables);

            Assert.AreEqual(result.errors.Count, 1);
            Assert.AreEqual(result.errors[0].message, "Invalid merchant account id: some_merchant");
        }
예제 #14
0
        public void ThrowExceptionIfGraphQLErrorResponseHasErrors_whenValidationAndNotFoundErrorClassesExist_throwsNotFoundException()
        {
            Dictionary <string, string> validationExtensions = new Dictionary <string, string>();

            validationExtensions.Add("errorClass", "VALIDATION");
            Dictionary <string, string> notFoundExtensions = new Dictionary <string, string>();

            notFoundExtensions.Add("errorClass", "NOT_FOUND");

            GraphQLError validationError = new GraphQLError();

            validationError.extensions = validationExtensions;
            GraphQLError notFoundError = new GraphQLError();

            notFoundError.extensions = notFoundExtensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(validationError);
            response.errors.Add(notFoundError);

            Assert.Throws <NotFoundException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }