public void GraphQLQueryGeneratorFromFields_Should_Throw_When_No_Matching_Argument_Found_Two_Arguments() { // Arrange var fieldGenerator = new GraphQLFieldBuilder(); var queryGenerator = new GraphQLQueryGeneratorFromFields(); var argument1 = new GraphQLQueryArgument("hello1Argument", "Value1"); var argument2 = new GraphQLQueryArgument("hello2Argument", "Value2"); // Act / Assert var exception = Assert.Throws <GraphQLArgumentVariableNotFoundException>(() => { // Get the query var query = queryGenerator.GetQuery(fieldGenerator.GetFields(typeof(SampleQuery)), argument1, argument2); }); // Assert // Should contain two element Assert.Equal(2, exception.Arguments.Count()); // Argument should contain helloArgument and value Assert.Contains(argument1, exception.Arguments); Assert.Contains(argument2, exception.Arguments); }
public void Test_Single_Field_Should_Not_Generate_Seperate_Field_And_Alias() { // Arrange var expected = "{\"query\":\"query{field}\"}"; var fieldBuilder = new GraphQLFieldBuilder(); var queryBuilder = new GraphQLQueryGeneratorFromFields(); // Act // Get fields var fields = fieldBuilder.GetFields(typeof(Query_Test_Single_Field_Should_Not_Generate_Seperate_Field_And_Alias)); var actual = queryBuilder.GetQuery(fields); // Assert Assert.Equal(expected, actual); }
public void Test_Case_Hero() { // Arrange var expected = "{\"query\":\"query{hero{friends{name} name}}\"}"; var fieldBuilder = new GraphQLFieldBuilder(); var queryBuilder = new GraphQLQueryGeneratorFromFields(); // Act // Get fields var fields = fieldBuilder.GetFields(typeof(Query_Test_Case_Hero)); var actual = queryBuilder.GetQuery(fields); // Assert Assert.Equal(expected, actual); }
public void Test_Variable_Complex_Dynamic_Type() { // Arrange var expected = "{\"query\":\"query($variableName:Type!){field(argumentName:$variableName)}\",\"variables\":{\"variableName\":{\"field1\":\"value1\",\"field2\":\"value2\"}}}"; var fieldBuilder = new GraphQLFieldBuilder(); var queryBuilder = new GraphQLQueryGeneratorFromFields(); // Act // Get fields var fields = fieldBuilder.GetFields(typeof(Query)); var actual = queryBuilder.GetQuery(fields, new GraphQLQueryArgument("variableName", new { field1 = "value1", field2 = "value2" })); // Assert Assert.Equal(expected, actual); }
public void GraphQLQueryGeneratorFromFields_Should_Throw_When_No_Matching_Argument_Found_And_Only_One_Of_2_Arguments_Found() { // Arrange var fieldGenerator = new GraphQLFieldBuilder(); var queryGenerator = new GraphQLQueryGeneratorFromFields(); // Act / Assert var exception = Assert.Throws <GraphQLArgumentVariableNotFoundException>(() => { // Get the query var query = queryGenerator.GetQuery(fieldGenerator.GetFields(typeof(SampleQuery2)), new GraphQLQueryArgument("hello1Argument", "Value1"), new GraphQLQueryArgument("hello2Argument", "Value2")); }); // Assert // Should contain one element Assert.Equal(1, exception.Arguments.Count()); // Argument should contain helloArgument and value Assert.Equal("hello2Argument", exception.Arguments.First().VariableName); Assert.Equal("Value2", exception.Arguments.First().ArgumentValue); }