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); }
public void SmokeTestQueryGraphQLWithoutVariables_isSuccessful() { BraintreeGraphQLService service = GetService(); var result = service.QueryGraphQL("query {\n ping\n}", null); Assert.AreEqual(result.data["ping"], "pong"); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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)); }
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)); }
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)); }
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)); }
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"); }
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)); }