Esempio n. 1
0
        public void Query_WithFragmentInsideSelectAndMultipleProperties_CreatesCorrectQueryThatDoesntCollideWithPropertyNames()
        {
            var networkClient = Substitute.For <INetworkClient>();
            var client        = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.Complex.ComplexArray.Select(a => new {
                    test1 = a.SimpleInterface.Test,
                    test2 = (a.SimpleInterface as SimpleObject).TestEnum
                })
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: complex{
    field0: complexArray{
      field0: simpleInterface{
        field0: test
        ... on SimpleObject {
          field1: testEnum
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 2
0
        public void CreateQuery_RequestForComplexObject_GeneratesCorrectQuery()
        {
            var client = new TestClient(null);

            var query = client.CreateQuery(e => new
            {
                o = e.Complex.Test,
                b = e.Complex.Complex.Complex.Test,
                c = e.Complex.Complex.Simple.Test
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: complex{
    field0: test
    field1: complex{
      field0: complex{
        field0: test
        __typename
      }
      field1: simple{
        field0: test
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 3
0
        public void Query_WithFragmentInsideSelect_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();
            var client        = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.Complex.ComplexArray.Select(a => (a.SimpleInterface as SimpleObject).TestEnum)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: complex{
    field0: complexArray{
      field0: simpleInterface{
        ... on SimpleObject {
          field0: testEnum
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 4
0
        public void Query_WithSimpleObjectArrayAndNestedSelectMethod_ShouldExpandSelectionListToFields()
        {
            var networkClient = Substitute.For <INetworkClient>();
            var client        = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.Complex.ComplexArray.Select(o => o.SimpleArray)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: complex{
    field0: complexArray{
      field0: simpleArray{
        test
        date
        testEnum
        testArray
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 5
0
        public void Query_InputTypeWithNull_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            var client = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.InputObj(new SomeInputObject {
                    Faz = 42, Bar = null
                })
            });

            var json = JsonConvert.SerializeObject(query, new JsonSerializerSettings()
            {
                Converters = new List <JsonConverter>()
                {
                    new GraphQLObjectConverter()
                },
                Formatting = Formatting.Indented
            });

            AssertUtils.AreEqualIgnoreLineBreaks(
                @"{
  ""query"": ""query Query($var_0: SomeInputObject) {\r\n  field0: test(input: $var_0)\r\n  __typename\r\n}"",
  ""variables"": {
    ""var_0"": {
      ""faz"": 42
    }
  }
}",
                json);
        }
Esempio n. 6
0
        public void CreateQuery_RequestForComplexObjectWithExernalParams_GeneratesCorrectQuery()
        {
            var client = new TestClient(null);

            var test1 = "test1";
            var test2 = "test2";
            var test3 = "test3";
            var test4 = "test4";

            var query = client.CreateQuery(e => new
            {
                o = e.ComplexWithParams(test1).Test,
                b = e.ComplexWithParams(test4).Complex.ComplexWithParams(test2).Complex.Test,
                c = e.ComplexWithParams(test1).ComplexWithParams2(test3, test4).Simple.Test
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: String!, $var_1: String!, $var_2: String!, $var_3: String!, $var_4: String!) {
  field0: complexWithParams(name: $var_0){
    field0: test
    field1: complexWithParams2(name: $var_1, surname: $var_2){
      field0: simple{
        field0: test
        __typename
      }
      __typename
    }
    __typename
  }
  field1: complexWithParams(name: $var_3){
    field0: complex{
      field0: complexWithParams(name: $var_4){
        field0: complex{
          field0: test
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}", query.Query);

            Assert.AreEqual("test1", query.Variables["var_0"]);
            Assert.AreEqual("test3", query.Variables["var_1"]);
            Assert.AreEqual("test4", query.Variables["var_2"]);
            Assert.AreEqual("test4", query.Variables["var_3"]);
        }
Esempio n. 7
0
        public void Query_DateTimeParameter_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            var client = new TestClient(networkClient);

            var dateTime = DateTime.Parse("2008-09-22T14:01:54.9571247Z").ToUniversalTime();

            var query = client.CreateQuery(e => new
            {
                test = e.DateTimeParam(dateTime)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: DateTime!) {
  field0: test(dt: $var_0)
  __typename
}", query.Query);

            Assert.AreEqual(dateTime, query.Variables["var_0"]);
        }
Esempio n. 8
0
        public void Query_NonNullToNullParameter_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            networkClient.Send(Arg.Any <GraphQLQueryInfo>()).Returns("{ field0: 1 }");

            var client = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.NullableParam(1)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: Int) {
  field0: test(arr: $var_0)
  __typename
}", query.Query);

            Assert.AreEqual(1, query.Variables["var_0"]);
        }
Esempio n. 9
0
        public void CreateQuery_RequestForSimpleObject_GeneratesCorrectQuery()
        {
            var client = new TestClient(null);

            var query = client.CreateQuery(e => new
            {
                o = new
                {
                    b = e.Object.Test
                }
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: object{
    field0: test
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 10
0
        public void CreateQuery_RequestWithSelect_GeneratesCorrectQuery()
        {
            var client = new TestClient(null);

            var query = client.CreateQuery(e => new
            {
                o = e.Complex.ComplexArray.Select(x => x.Test)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: complex{
    field0: complexArray{
      field0: test
      __typename
    }
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 11
0
        public void Query_ArrayAsParameter_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            networkClient.Send(Arg.Any <GraphQLQueryInfo>()).Returns("{ field0: 1 }");

            var client = new TestClient(networkClient);
            var param  = new int[] { 1, 2, 3 };

            var query = client.CreateQuery(e => new
            {
                test = e.ArrayAsParameter(param)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: [Int!]!) {
  field0: test(arr: $var_0)
  __typename
}", query.Query);

            Assert.AreEqual(param, query.Variables["var_0"]);
        }
Esempio n. 12
0
        public void CreateQuery_RequestForSimpleScalar_GeneratesCorrectQuery()
        {
            var client = new TestClient(null);

            var query = client.CreateQuery(e => new
            {
                test  = e.Test,
                test2 = e.Object.TestWithParams(0.5f)
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: Float!) {
  field0: test
  field1: object{
    field0: testWithParams(x: $var_0)
    __typename
  }
  __typename
}", query.Query);

            Assert.AreEqual(0.5f, query.Variables["var_0"]);
        }
Esempio n. 13
0
        public void Query_WithSimpleObject_ShouldExpandSelectionListToFields()
        {
            var networkClient = Substitute.For <INetworkClient>();
            var client        = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.Object
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query {
  field0: object{
    test
    date
    testEnum
    testArray
    __typename
  }
  __typename
}", query.Query);
        }
Esempio n. 14
0
        public void Query_InputType_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            var client = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.InputObj(new SomeInputObject {
                    Faz = 42,
                    Bar = null
                })
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: SomeInputObject) {
  field0: test(input: $var_0)
  __typename
}", query.Query);

            Assert.AreEqual(42, ((SomeInputObject)query.Variables["var_0"]).Faz);
            Assert.AreEqual(null, ((SomeInputObject)query.Variables["var_0"]).Bar);
        }
Esempio n. 15
0
        public void Query_ArrayInputType_CreatesCorrectQuery()
        {
            var networkClient = Substitute.For <INetworkClient>();

            var client = new TestClient(networkClient);

            var query = client.CreateQuery(e => new
            {
                test = e.ArrayOfInputObj(new[]
                {
                    new SomeInputObject {
                        Faz = 42, Bar = null
                    },
                    new SomeInputObject {
                        Faz = 12, Bar = "test"
                    }
                })
            });

            AssertUtils.AreEqualIgnoreLineBreaks(@"query Query($var_0: [SomeInputObject]) {
  field0: test(input: $var_0)
  __typename
}", query.Query);
        }