public void TestTypeQLMultipleQuery()
        {
            IQueryType queryType0 = new QueryType("states", new Fields(
                                                      new Field("id"),
                                                      new Field("uf"),
                                                      new Field(new QueryType("contries", new Fields(
                                                                                  new Field("id"),
                                                                                  new Field("name")
                                                                                  ))))
                                                  );

            IQueryType queryType1 = new QueryType("contries", new Fields(
                                                      new Field("id"),
                                                      new Field("name")
                                                      )
                                                  );

            ITypeQL typeQL0 = new TypeQL(queryType0, queryType1);

            Assert.IsTrue(typeQL0.QueryTypes.Length == 2);
            Assert.IsNull(typeQL0.Variables);
            string expected0 = "{\"query\":\"{states{id,uf,contries{id,name}}contries{id,name}}\"}";

            Assert.AreEqual(expected0, typeQL0.ToStringJson());
        }
        public void TestTypeQLMultipleQueryAndVariables()
        {
            Variables  variables  = new Variables("get", new Variable <bool>("load", true));
            IQueryType queryType0 = new QueryType("states", new Fields(
                                                      new Field("id"),
                                                      new Field("uf"),
                                                      new Field(new QueryType("contries", new Fields(
                                                                                  new Field("id"),
                                                                                  new Field("name")
                                                                                  ))))
                                                  );

            IQueryType queryType1 = new QueryType("contries", new Fields(
                                                      new Field("id"),
                                                      new Field("name")
                                                      )
                                                  );

            ITypeQL typeQL0 = new TypeQL(variables, queryType0, queryType1);

            Assert.IsTrue(typeQL0.QueryTypes.Length == 2);
            Assert.IsNotNull(typeQL0.Variables);
            Assert.IsTrue(typeQL0.Variables.Count == 1);
            string expected0 = "{\"query\":\"query get($load:Boolean){states{id,uf,contries{id,name}}contries{id,name}}\",\"variables\":{\"load\":true}}";

            Assert.AreEqual(expected0, typeQL0.ToStringJson());
        }
        public void TestConvertTimeSpan()
        {
            Source source = new Source()
            {
                Id   = 0,
                Time = DateTime.Parse("01/01/1991")
            };
            TypeQL typeQL = new TypeQL(
                new Variables("getSource",
                              new Variable <object>("input", source, "source_input")
                              ),
                new QueryType("source_add",
                              new Fields(
                                  new Field("id"),
                                  new Field("name"),
                                  new Field("value"),
                                  new Field("active"),
                                  new Field("created"),
                                  new Field("time")
                                  ),
                              new Arguments(
                                  new Argument(
                                      new Parameter("input")
                                      )
                                  )
                              )
                );

            string expected = "{\"query\":\"query getSource($input:source_input){source_add(input:$input){id,name,value,active,created,time}}\",\"variables\":{\"input\":{\"id\":0,\"name\":null,\"value\":null,\"created\":null,\"active\":null,\"time\":\"1991-01-01T00:00:00\"}}}";

            Assert.AreEqual(expected, typeQL.ToStringJson());
        }
        public void TestVariablesNullable()
        {
            Source source = new Source();
            TypeQL typeQL = new TypeQL(
                new Variables("getSource",
                              new Variable <object>("input", source, "source_input", format: Format.FormatClass)
                              ),
                new QueryType("source_add",
                              new Fields(
                                  new Field("id"),
                                  new Field("name"),
                                  new Field("value"),
                                  new Field("active"),
                                  new Field("created"),
                                  new Field("time")
                                  ),
                              new Arguments(
                                  new Argument(
                                      new Parameter("input")
                                      )
                                  )
                              )
                );
            string expected = "{\"query\":\"query getSource($input:source_input){source_add(input:$input){id,name,value,active,created,time}}\",\"variables\":{\"input\":{\"id\":0,\"name\":null,\"value\":null,\"created\":null,\"active\":null,\"time\":null}}}";

            Assert.AreEqual(expected, typeQL.ToStringJson());
        }
        public void TestParamFullNullable()
        {
            TypeQL typeQL = new TypeQL(
                new QueryType("source_param_add",
                              new Fields(
                                  new Field("id"),
                                  new Field("name"),
                                  new Field("value"),
                                  new Field("active"),
                                  new Field("created"),
                                  new Field("time")
                                  ),
                              new Arguments(
                                  new Argument("id", null),
                                  new Argument("name", null),
                                  new Argument("value", null),
                                  new Argument("active", null),
                                  new Argument("created", null),
                                  new Argument("time", null)
                                  )
                              )
                );

            string expected = "{\"query\":\"{source_param_add(id:null,name:null,value:null,active:null,created:null,time:null){id,name,value,active,created,time}}\"}";

            Assert.AreEqual(expected, typeQL.ToStringJson());
        }
        public void TestTypeQL()
        {
            IQueryType queryType = new QueryType("name", new Fields(new Field("id")));
            Variables  variables = new Variables("get", new Variable <int>("id", 1));
            ITypeQL    typeQL0   = new TypeQL(queryType);
            ITypeQL    typeQL1   = new TypeQL(variables, queryType);
            ITypeQL    typeQL2   = new TypeQL(variables,
                                              new Fragments(
                                                  new Fragment(
                                                      new QueryType("get", new Fields("id", "name"))
                                                      )
                                                  )
                                              );

            Assert.IsNotNull(typeQL2.Fragments);
            Assert.IsTrue(typeQL2.Fragments.Count == 1);
            Assert.IsNotNull(typeQL2.Variables);

            Assert.IsTrue(typeQL0.QueryTypes.Length == 1);
            Assert.IsNull(typeQL0.Variables);
            Assert.IsTrue(typeQL1.QueryTypes.Length == 1);
            Assert.IsNotNull(typeQL1.Variables);
            Assert.IsTrue(typeQL1.Variables.Count == 1);

            string expected0 = "{\"query\":\"{name{id}}\"}";
            string expected1 = "{\"query\":\"query get($id:Int){name{id}}\",\"variables\":{\"id\":1}}";

            Assert.AreEqual(expected0, typeQL0.ToStringJson());
            Assert.AreEqual(expected1, typeQL1.ToStringJson());

            Assert.IsInstanceOfType(queryType, typeof(IQueryType));
            Assert.IsInstanceOfType(variables, typeof(Variables));
            Assert.IsInstanceOfType(typeQL0, typeof(ITypeQL));
            Assert.IsInstanceOfType(typeQL1, typeof(ITypeQL));
            Assert.IsInstanceOfType(typeQL0.ToStringJson(), typeof(string));
            Assert.IsInstanceOfType(typeQL1.ToStringJson(), typeof(string));
        }
        public void TestCarsWithDirective()
        {
            var queryType = new QueryType(
                name: "cars",
                fields: new Fields(
                    new Field("id", new IDirective[] { new Include("status") }),
                    new Field("title", new IDirective[] { new Skip("status") })
                    ),
                arguments: new Arguments(
                    new Argument(new Parameter("status"))
                    )
                );
            var typeQLTest = new TypeQL(
                new Variables("get",
                              new Variable <bool>("status", true, true, true, Format.FormatBool)
                              ),
                queryType
                );

            Assert.AreEqual("{\"query\":\"query get($status:Boolean!=true){cars(status:$status){id @include(if:$status),title @skip(if:$status)}}\",\"variables\":{\"status\":true}}", typeQLTest.ToStringJson());
        }