示例#1
0
        public IEnumerator LoadProductsById()
        {
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            Clients.GraphQL.products(
                (products, error) => {
                waiter.Stop();

                Assert.IsNull(error, "No errors");
                Assert.AreEqual(2, products.Count, "Loaded 2 products");
                Assert.AreEqual("Arena Zip Boot", products[0].title(), "Title product 0: Snare Boot");
                Assert.AreEqual("Pin Boot", products[1].title(), "Title product 1: Neptune Boot");

                List <string> aliases = Utils.GetImageAliases();

                var productImages = (List <Image>)products[0].images();
                foreach (string imageAlias in aliases)
                {
                    Assert.IsNotNull(productImages[0].transformedSrc(imageAlias), string.Format("images alias {0} was queried", imageAlias));
                }

                List <ProductVariant> variants = (List <ProductVariant>)products[0].variants();

                // this will throw an exception if not queried
                variants[0].image();

                Assert.IsNotNull(products[0].images(), "images with no alias queried");
            },
                "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODE0NzU=", "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODQyOTE="
                );

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }
        public IEnumerator CanQueryTwoShops()
        {
            string domain1        = "graphql.myshopify.com";
            string authorization1 = "351c122017d0f2a957d32ae728ad749c";
            string domain2        = "graphql-many-products.myshopify.com";
            string authorization2 = "43b7fef8bd2f27f1d645586b72c9b825";

            StoppableWaitForTime waiter = Utils.GetWaitQuery();
            List <string>        names  = new List <string>();

            QueryLoader queryLoader1 = new QueryLoader(new UnityLoader(domain1, authorization1));
            QueryLoader queryLoader2 = new QueryLoader(new UnityLoader(domain2, authorization2));

            QueryResponseHandler callback = (QueryResponse response) => {
                names.Add(response.data.shop().name());

                if (names.Count == 2)
                {
                    waiter.Stop();
                }
            };

            queryLoader1.Query(TestQueries.Query, callback);
            queryLoader2.Query(TestQueries.Query, callback);

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
            Assert.AreNotEqual(names[0], names[1]);
        }
示例#3
0
        public IEnumerator Load3Products()
        {
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            Clients.GraphQL.products(
                first: 3,
                callback: (products, error, after) => {
                waiter.Stop();

                Assert.IsNull(error, "No errors");
                Assert.AreEqual(3, products.Count, "Loaded 3 products");
                Assert.AreEqual("Snare Boot", products[0].title(), "Title product 0: Snare Boot");
                Assert.AreEqual("Neptune Boot", products[1].title(), "Title product 1: Neptune Boot");

                List <string> aliases = Utils.GetImageAliases();

                var productImages = (List <Image>)products[0].images();
                foreach (string imageAlias in aliases)
                {
                    Assert.IsNotNull(productImages[0].transformedSrc(imageAlias), string.Format("images alias {0} was queried", imageAlias));
                }

                List <ProductVariant> variants = (List <ProductVariant>)products[0].variants();

                // this will throw an exception if not queried
                variants[0].image();

                Assert.IsNotNull(products[0].images(), "images with no alias queried");
            }
                );

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }
示例#4
0
        public IEnumerator LoadCollectionsById()
        {
            ShopifyBuy.Init("43b7fef8bd2f27f1d645586b72c9b825", "graphql-many-products.myshopify.com");

            StoppableWaitForTime waiter = Utils.GetWaitQuery();
            var collectionIds           = new List <string>()
            {
                "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzUzNTk4NjE3OA==",
                "Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzUzOTYyMzQyNg=="
            };

            List <Collection> foundCollections = null;

            ShopifyBuy.Client().collections(
                collectionIds: collectionIds,
                callback: (collections, error) => {
                waiter.Stop();
                foundCollections = collections;
            }
                );

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);

            for (var i = 0; i < collectionIds.Count; i++)
            {
                Assert.AreEqual(collectionIds[i], foundCollections[i].id());
            }
        }
示例#5
0
        public IEnumerator LoadACollection()
        {
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            Clients.GraphQLMany.collections(
                first: 1,
                callback: (collections, error, after) => {
                waiter.Stop();

                Assert.IsNull(error, "No errors");
                Assert.AreEqual(1, collections.Count, "Loaded 1 collection");
                Assert.AreEqual("Home page", collections[0].title(), "First collection is: Home page");

                List <string> aliases = Utils.GetImageAliases();

                foreach (string alias in aliases)
                {
                    // this will throw an exception if image was not queried with alias
                    // no collections in our test store have values
                    collections[0].image().transformedSrc(alias);
                }
            }
                );

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }
        public IEnumerator Loads20ProductsInLessThan6Seconds()
        {
            float maxDuration                      = 6f;
            int   maxProducts                      = 20;
            StoppableWaitForTime waiter            = new StoppableWaitForTime(maxDuration);
            ShopifyError         errorsFromQueries = null;
            List <Product>       AllProducts       = new List <Product>();

            Action <string> loadPage = null;

            loadPage = (string after) => {
                Clients.GraphQLMany.products((products, errors, afterProductsLoaded) => {
                    if (products != null)
                    {
                        AllProducts.AddRange(products);
                    }

                    if (errors != null)
                    {
                        errorsFromQueries = errors;
                        waiter.Stop();
                    }
                    else if (afterProductsLoaded == null || AllProducts.Count >= maxProducts)
                    {
                        waiter.Stop();
                    }
                    else
                    {
                        loadPage(afterProductsLoaded);
                    }
                }, after: after);
            };

            loadPage(null);

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, "Query did not complete in " + maxDuration + " seconds");
            Assert.IsNull(errorsFromQueries);
            Assert.GreaterOrEqual(AllProducts.Count, maxProducts);
        }
示例#7
0
        public IEnumerator LoadAllCollections()
        {
            float maxDuration                      = 8f;
            int   maxCollections                   = 13;
            StoppableWaitForTime waiter            = new StoppableWaitForTime(maxDuration);
            ShopifyError         errorsFromQueries = null;
            List <Collection>    AllCollections    = new List <Collection>();

            Action <string> loadPage = null;

            loadPage = (string after) => {
                Clients.GraphQLMany.collections((collections, errors, afterCollectionsLoaded) => {
                    if (collections != null)
                    {
                        AllCollections.AddRange(collections);
                    }

                    if (errors != null)
                    {
                        errorsFromQueries = errors;
                        waiter.Stop();
                    }
                    else if (afterCollectionsLoaded == null || AllCollections.Count >= maxCollections)
                    {
                        waiter.Stop();
                    }
                    else
                    {
                        loadPage(afterCollectionsLoaded);
                    }
                }, after: after);
            };

            loadPage(null);

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, "Query did not complete in " + maxDuration + " seconds");
            Assert.IsNull(errorsFromQueries);
            Assert.GreaterOrEqual(AllCollections.Count, maxCollections);
        }
示例#8
0
        public IEnumerator LoadShopName()
        {
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            Clients.GraphQL.Query(
                (q) => q.shop(s => s
                              .name()
                              ),
                (data, error) => {
                waiter.Stop();
                Assert.IsNull(error, "No errors");
                Assert.AreEqual("graphql", data.shop().name(), "Shop name was \"graphql\"");
            }
                );

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }
        public IEnumerator RanQueryUsingUnityLoader()
        {
            string domain               = "graphql.myshopify.com";
            string authorization        = "351c122017d0f2a957d32ae728ad749c";
            StoppableWaitForTime waiter = Utils.GetWaitQuery();

            QueryLoader queryLoader = new QueryLoader(new UnityLoader(domain, authorization));

            queryLoader.Query(TestQueries.Query, (QueryResponse response) => {
                waiter.Stop();

                Assert.IsNull(response.HTTPError, "http errors were not null: " + response.HTTPError);
                Assert.IsNull(response.errors, "GraphQL errors were null");
                Assert.IsNotNull(response.data, "Received a response");
                Assert.AreEqual("graphql", response.data.shop().name());
            });

            yield return(waiter);

            Assert.IsTrue(waiter.IsStopped, Utils.MaxQueryMessage);
        }