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); }
public void TestGQLFieldGetArgumentString ( string testName1, object testVal1, string isPrimitive1, string testName2, object testVal2, string isPrimitive2 ) { bool isPrim1 = bool.Parse(isPrimitive1); bool isPrim2 = String.IsNullOrEmpty(isPrimitive2) ? false : bool.Parse(isPrimitive2); GQLField testField = new GQLField { Field = new KeyValuePair <string, object>("Field1", "") }; GQLArgument arg1 = new GQLArgument { Name = testName1, Value = testVal1, IsPrimitiveType = isPrim1 }; testField.Arguments = new List <IGQLQueryArgument>(); testField.Arguments.Add(arg1); StringBuilder expected = new StringBuilder("("); if (isPrim1) { expected.Append($"{testName1}:{testVal1}"); } else { expected.Append($"{testName1}:${testVal1}"); } if (String.IsNullOrEmpty(testName2) != true) { GQLArgument arg2 = new GQLArgument { Name = testName2, Value = testVal2, IsPrimitiveType = isPrim2 }; testField.Arguments.Add(arg2); if (isPrim2) { expected.Append($",{testName2}:{testVal2}"); } else { expected.Append($",{testName2}:${testVal2}"); } } expected.Append(")"); Assert.AreEqual(expected.ToString(), testField.GetArgumentsString()); }