public void TestGQLArgument(string argName, object argValue, string isPrimitive) { bool isPrim = Boolean.Parse(isPrimitive); GQLArgument testArgs = new GQLArgument { Name = argName, Value = argValue, IsPrimitiveType = isPrim }; var expected = isPrim ? $"{argName}:{argValue}" : $"{argName}:${argValue}"; Assert.AreEqual(expected, testArgs.ToGQLString()); }
public void TestGQLFieldToGQLString ( string testName1, object testVal1, bool isNested, bool isRequest, bool withArg ) { StringBuilder expected = new StringBuilder(); GQLField subField = new GQLField { Field = new KeyValuePair <string, object>("innerField", (!isRequest)?"innerValue":null), IsNested = false, IsRequest = isRequest }; if (isNested) { testVal1 = subField; } GQLField field = new GQLField { IsNested = isNested, IsRequest = isRequest }; GQLArgument arg1 = new GQLArgument { Name = "fArg1", IsPrimitiveType = true, Value = "testFArg1" }; if (withArg) { field.Arguments = new List <IGQLQueryArgument>(); field.Arguments.Add(arg1); } if (isNested) { field.Field = new KeyValuePair <string, object>(testName1, testVal1); } else { if (!isRequest) { field.Field = new KeyValuePair <string, object>(testName1, testVal1); } else { field.Field = new KeyValuePair <string, object>(testName1, null); } } var result = field.ToGQLString(); Console.WriteLine($"result = {result}"); if (!isNested) { if (!isRequest) { expected.Append($"{testName1}:{testVal1}"); } else { expected.Append(testName1); if (withArg) { expected.Append("("); expected.Append(arg1.ToGQLString()); expected.Append(")"); } } } else { if (!isRequest) { expected.Append($"{testName1}:"); expected.Append($"{{{subField.Field.Key}:{subField.Field.Value}}}"); } else { expected.Append(testName1); if (withArg) { expected.Append("("); expected.Append(arg1.ToGQLString()); expected.Append(")"); } expected.Append($"{{innerField}}"); } } Console.WriteLine($"expected = {expected}"); Assert.AreEqual(expected.ToString(), result); }