Exemplo n.º 1
0
        public void TopLevelHandlesListExceptions()
        {
            string stringJSON = @"{
                ""errors"": [
                    {
                        ""message"": ""Field 'doesntExist' doesn't exist on type 'Shop'"",
                        ""locations"": [
                            {
                                ""line"": 3,
                                ""column"": 5
                            }
                        ],
                        ""fields"": [
                            ""query"",
                            ""shop"",
                            ""doesntExist""
                        ]
                    }
                ]
            }";

            Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON);

            TopLevelResponse response = new TopLevelResponse(dataJSON);

            Assert.IsNull(response.DataJSON);
            Assert.IsNotNull(response.errors);
            Assert.AreEqual("[\"Field 'doesntExist' doesn't exist on type 'Shop'\"]", response.errors);
        }
Exemplo n.º 2
0
        public void TopLevelCastableToShopifyError()
        {
            string stringJSON = @"{
                ""errors"": [
                    {
                        ""message"": ""Field 'doesntExist' doesn't exist on type 'Shop'"",
                        ""locations"": [
                            {
                                ""line"": 3,
                                ""column"": 5
                            }
                        ],
                        ""fields"": [
                            ""query"",
                            ""shop"",
                            ""doesntExist""
                        ]
                    }
                ]
            }";

            Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON);

            TopLevelResponse response = new TopLevelResponse(dataJSON);

            Assert.IsNull(response.DataJSON);
            Assert.IsNotNull(response.errors);

            ShopifyError error = (ShopifyError)response;

            Assert.IsNotNull(error);
            Assert.IsTrue(error is ShopifyError);
            Assert.AreEqual(ShopifyError.ErrorType.GraphQL, error.Type);
            Assert.AreEqual("[\"Field 'doesntExist' doesn't exist on type 'Shop'\"]", error.Description);
        }
Exemplo n.º 3
0
        public void TopLevelReturnsData()
        {
            string stringJSON = @"{
                ""data"": {
                    ""shop"": { 
                        ""name"": ""test-shop""
                    }
                }
            }";

            Dictionary <string, object> dataJSON = (Dictionary <string, object>)Json.Deserialize(stringJSON);

            TopLevelResponse response = new TopLevelResponse(dataJSON);

            Assert.IsNotNull(response.DataJSON);
            Assert.IsNull(response.errors);
        }