public async Task Methods_Perform_Async() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(PerformanceSchema)); var query = @"{ slow1:slowCall{ date } slow2:slowCall{ date } slow3:slowCall{ date } }"; var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await DocumentOperations.ExecuteOperationsAsync(schema, null, query, validate : false); stopwatch.Stop(); Assert.IsTrue(stopwatch.Elapsed.TotalSeconds < 2); Assert.IsNull(result.Errors); }
public async void OperationLimit_WhenNotExceeded_Runs() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoSchema)); var query = @"{ testRequest {value} t2:testRequest {value} }"; await DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes : 2); }
public async void OperationLimit_WhenExceeded_Throws() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoSchema)); var query = @"{ testRequest {value} t2:testRequest {value} }"; await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes: 1)); }
public static void QueryOperationsSuccess(GraphQL.Types.Schema schema, string query, string expected, string variables = null, bool compareBoth = true) { var result2 = DocumentOperations.ExecuteOperationsAsync(schema, null, query, variables?.ToInputs()).Result; var writtenResult2 = JsonConvert.SerializeObject(result2.Data); var queryResult = CreateQueryResult(expected); var expectedResult = JsonConvert.SerializeObject(queryResult.Data); var errors = result2.Errors?.FirstOrDefault(); //for easy debugging var allTypes = schema.AllTypes; Assert.Null(errors?.Message); Assert.Equal(expectedResult, writtenResult2); }
public async void BasicExample_WithoutInt_Fails() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoStateSchema)); var query = @" mutation SetState{ set(request:{decimal:24.15}){ decimal } } "; var result = await DocumentOperations.ExecuteOperationsAsync(schema, null, query); Assert.IsTrue(result.Errors.Any()); }
public async void OperationLimit_WhenNotExceededWithMutations_Runs() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoStateSchema)); var query = @" mutation SetState{ setState (request:Open){ state } } query GetState{ getState{ state } } "; await DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes : 2); }
public async void OperationLimit_WhenExceededWithMutations_Throws() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoStateSchema)); var query = @" mutation SetState{ setState (request:Open){ state } } query GetState{ getState{ state } } "; await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes: 1)); }
public static void QuerySuccess(GraphQL.Types.Schema schema, string query, string expected, string variables = null, bool compareBoth = true) { var exec = new DocumentExecuter(new GraphQLDocumentBuilder(), new DocumentValidator(), new ComplexityAnalyzer()); var result = exec.ExecuteAsync(schema, null, query, null, variables?.ToInputs()).Result; var result2 = DocumentOperations.ExecuteOperationsAsync(schema, null, query, variables?.ToInputs()).Result; var writtenResult = JsonConvert.SerializeObject(result.Data); var writtenResult2 = JsonConvert.SerializeObject(result2.Data); var queryResult = CreateQueryResult(expected); var expectedResult = JsonConvert.SerializeObject(queryResult.Data); var errors = result.Errors?.FirstOrDefault(); var errors2 = result2.Errors?.FirstOrDefault(); //for easy debugging var allTypes = schema.AllTypes; Assert.IsNull(errors?.Message); Assert.IsNull(errors2?.Message); Assert.AreEqual(expectedResult, writtenResult); Assert.AreEqual(expectedResult, writtenResult2); }
public async Task LargeLists_Perform_UnderThreshold() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(PerformanceSchema)); var query = @"{ testList{ date enum value nullValue decimalValue timeSpan byteArray stringValue values{ value{ complicatedResponse{ echo data } } } } }"; var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await DocumentOperations.ExecuteOperationsAsync(schema, null, query, validate : false); stopwatch.Stop(); _output.WriteLine($"Total Milliseconds: {stopwatch.ElapsedMilliseconds}"); Assert.True(stopwatch.Elapsed.TotalSeconds < 2); Assert.Null(result.Errors); }
public async void OperationLimit_WhenNotExceededWithParameters_Runs() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(EchoStateSchema)); var query = @" mutation SetState($begin: Date!, $end: Date!, $test: String, $test2: String){ setState (request:Open){ state } } query GetState($begin: Date!, $end: Date!, $test: String, $test2: String){ getState{ state } state2:getState{ state } } "; await DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes : 3); }