private void SetupQueriesOnNode()
        {
            QueryRootQuery query = new QueryRootQuery();

            query.node(n => n
                       .onCollection(c => c
                                     .id()
                                     .products(pc => DefaultQueries.collections.ProductConnection(pc),
                                               first: DefaultQueries.MaxPageSize, after: "product249"
                                               )
                                     ),
                       id: "0", alias: "a0"
                       );

            string response = String.Format(@"{{
                ""data"": {{
                    ""node___a0"": {{
                        ""__typename"": ""Collection"",
                        ""id"": ""0"",
                        ""products"": {{
                            ""edges"": [
                                {0}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {1}
                            }}
                        }}
                    }}
                }}
            }}", GetProductOnCollections(1, 1, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(false));

            AddResponse(query, response);
        }
        private void SetupQueriesOnShopCollections()
        {
            for (int i = 0; i < CountPages; i++)
            {
                QueryRootQuery query = new QueryRootQuery();

                DefaultQueries.collections.ShopCollections(
                    query: query,
                    first: DefaultQueries.MaxPageSize,
                    after: i > 0 ? (i * DefaultQueries.MaxPageSize - 1).ToString() : null,
                    imageResolutions: ShopifyClient.DefaultImageResolutions
                    );

                string response = String.Format(@"{{
                    ""data"": {{
                        ""shop"": {{
                            ""collections"": {{
                                ""edges"": [
                                    {0}
                                ],
                                ""pageInfo"": {{
                                    ""hasNextPage"": {1}
                                }}
                            }}
                        }}
                    }}
                }}", GetCollectionEdges(i), UtilsMockLoader.GetJSONBool(i < CountPages - 1));

                AddResponse(query, response);
            }
        }
Пример #3
0
        private string GetImagesConnection(int page, int countImages, bool hasNextPage)
        {
            StringBuilder imagesResponse = new StringBuilder();

            imagesResponse.Append(String.Format(@"
                ""images"": {{
                    ""edges"": [
                        {0}
                    ],
                    ""pageInfo"": {{
                        ""hasNextPage"": {1}
                    }}
                }},
            ", GetImageNodes(page, countImages), UtilsMockLoader.GetJSONBool(hasNextPage)));

            int numAliasIterated = 0;

            foreach (string alias in ShopifyClient.DefaultImageResolutions.Keys)
            {
                string aliasedImages = String.Format(@"
                    ""images___{0}"": {{
                        ""edges"": [
                            {1}
                        ],
                        ""pageInfo"": {{
                            ""hasNextPage"": {2}
                        }}
                    }}
                ",
                                                     alias,
                                                     GetImageNodes(page, countImages),
                                                     UtilsMockLoader.GetJSONBool(hasNextPage));

                imagesResponse.Append(aliasedImages);

                if (numAliasIterated < ShopifyClient.DefaultImageResolutions.Keys.Count - 1)
                {
                    imagesResponse.Append(",");
                }

                numAliasIterated++;
            }

            return(imagesResponse.ToString());
        }
        private string GetCollectionEdges(int page)
        {
            StringBuilder edges = new StringBuilder();

            for (int i = 0; i < DefaultQueries.MaxPageSize; i++)
            {
                int  collection          = page * DefaultQueries.MaxPageSize + i;
                bool productsHasNextPage = collection == 0;

                StringBuilder resolutionImageResponses = new StringBuilder();
                int           numAliasIterated         = 0;
                foreach (string alias in ShopifyClient.DefaultImageResolutions.Keys)
                {
                    string aliasedImages = String.Format(@"
                        ""image___{0}"": {{
                            ""altText"": ""I am an image {0}"",
                            ""src"": ""http://cdn.com/images/collection{0}""
                        }}
                    ",
                                                         alias);

                    resolutionImageResponses.Append(aliasedImages);

                    if (numAliasIterated < ShopifyClient.DefaultImageResolutions.Keys.Count - 1)
                    {
                        resolutionImageResponses.Append(",");
                    }

                    numAliasIterated++;
                }

                edges.Append(String.Format(@"{{
                    ""node"": {{
                        ""id"": ""{0}"",
                        ""image"": {{
                            ""altText"": ""I am an image {0}"",
                            ""src"": ""http://cdn.com/images/collection{0}""
                        }},
                        ""title"": ""I am collection {0}"",
                        ""updatedAt"": ""2016-09-11T21:32:43Z"",
                        ""products"": {{
                            ""edges"": [
                                {1}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {2}
                            }}
                        }},
                        {3}
                    }},
                    ""cursor"": ""{0}""
                }}{4}",
                                           collection,
                                           GetProductOnCollections(0, collection, productsHasNextPage ? DefaultQueries.MaxPageSize : 1),
                                           UtilsMockLoader.GetJSONBool(productsHasNextPage),
                                           resolutionImageResponses.ToString(),
                                           i < DefaultQueries.MaxPageSize - 1 ? "," : ""));
            }

            return(edges.ToString());
        }
Пример #5
0
        private string GetProductEdges(int page)
        {
            StringBuilder edges = new StringBuilder();

            for (int i = 0; i < DefaultQueries.MaxPageSize; i++)
            {
                int  product             = page * DefaultQueries.MaxPageSize + i;
                bool imagesHasNextPage   = product == 1 || product == 2;
                bool variantsHasNextPage = product == 2;

                StringBuilder resolutionImageResponses = new StringBuilder();

                int numAliasIterated = 0;
                foreach (string alias in ShopifyClient.DefaultImageResolutions.Keys)
                {
                    string aliasedImages = String.Format(@"
                        ""images___{0}"": {{
                            ""edges"": [
                                {1}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {2}
                            }}
                        }}
                    ",
                                                         alias,
                                                         GetImageNodes(0, 1),
                                                         UtilsMockLoader.GetJSONBool(false));

                    resolutionImageResponses.Append(aliasedImages);

                    if (numAliasIterated < ShopifyClient.DefaultImageResolutions.Keys.Count - 1)
                    {
                        resolutionImageResponses.Append(",");
                    }

                    numAliasIterated++;
                }

                edges.Append(String.Format(@"{{
                    ""cursor"": ""{0}"",
                    ""node"": {{
                        ""id"": ""{0}"",
                        ""title"": ""Product{0}"",
                        ""descriptionHtml"": ""<div>This is product {0}</div>"",
                        ""options"": [
                            {{
                                ""name"": ""default option"",
                                ""values"": [""default-opt""]
                            }}
                        ],
                        ""variants"": {{
                            ""edges"": [
                                {3}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {4}
                            }}
                        }},
                        ""collections"": {{
                            ""edges"": [
                                {5}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {6}
                            }}
                        }},
                        ""images"": {{
                            ""edges"": [
                                {1}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {2}
                            }}
                        }},
                        {7}
                    }}
                }}{8}",
                                           product,
                                           GetImageNodes(0, imagesHasNextPage ? DefaultQueries.MaxPageSize : 1),
                                           UtilsMockLoader.GetJSONBool(imagesHasNextPage),
                                           GetVariants(0, product, variantsHasNextPage ? DefaultQueries.MaxPageSize : 1),
                                           UtilsMockLoader.GetJSONBool(variantsHasNextPage),
                                           GetCollectionsOnProduct(0, product, 1),
                                           UtilsMockLoader.GetJSONBool(false),
                                           resolutionImageResponses.ToString(),
                                           i < DefaultQueries.MaxPageSize - 1 ? "," : ""));
            }

            return(edges.ToString());
        }
Пример #6
0
        public void SetupQueriesOnNodeForProducts()
        {
            QueryRootQuery query = new QueryRootQuery();

            query.node(n => n
                       .onProduct(p => DefaultQueries.products.Product(p, ShopifyClient.DefaultImageResolutions)),
                       id: "productId333", alias: "a0"
                       );

            query.node(n => n
                       .onProduct(p => DefaultQueries.products.Product(p, ShopifyClient.DefaultImageResolutions)),
                       id: "productId444", alias: "a1"
                       );

            string response = String.Format(@"{{
                ""data"": {{
                    ""node___a0"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""productId333"",
                        {0},
                        ""variants"": {{
                            ""edges"": [
                                {2}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {3}
                            }}
                        }},
                        ""collections"": {{
                            ""edges"": [
                                {{
                                    ""node"": {{
                                        ""id"": ""0"",
                                        ""title"": ""I am collection 0"",
                                        ""updatedAt"": ""2016-09-11T21:32:43Z""
                                    }},
                                    ""cursor"": ""0""
                                }}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": false
                            }}
                        }}
                    }},
                    ""node___a1"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""productId444"",
                        {1},
                        ""variants"": {{
                            ""edges"": [
                                {2}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {3}
                            }}
                        }},
                        ""collections"": {{
                            ""edges"": [
                                {{
                                    ""node"": {{
                                        ""id"": ""0"",
                                        ""title"": ""I am collection 0"",
                                        ""updatedAt"": ""2016-09-11T21:32:43Z""
                                    }},
                                    ""cursor"": ""0""
                                }}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": false
                            }}
                        }}
                    }}
                }}
            }}", GetImagesConnection(0, DefaultQueries.MaxPageSize, true), GetImagesConnection(0, DefaultQueries.MaxPageSize, false), GetVariants(1, 2, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(false));

            AddResponse(query, response);

            query = new QueryRootQuery();

            query.node(
                n => n
                .onProduct((p) => {
                p.id()
                .images((ic) => { DefaultQueries.products.ImageConnection(ic); },
                        DefaultQueries.MaxPageSize, "image249"
                        );

                foreach (string alias in ShopifyClient.DefaultImageResolutions.Keys)
                {
                    string currentAlias = alias;

                    p.images((ic) => { DefaultQueries.products.ImageConnection(ic); },
                             DefaultQueries.MaxPageSize,
                             "image249",
                             null,
                             ShopifyClient.DefaultImageResolutions[currentAlias],
                             ShopifyClient.DefaultImageResolutions[currentAlias],
                             null,
                             null,
                             currentAlias
                             );
                }
            }
                           ),
                id: "productId333", alias: "a0"
                );

            response = String.Format(@"{{
                ""data"": {{
                    ""node___a0"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""productId333"",
                        {0}
                    }}
                }}
            }}", GetImagesConnection(1, DefaultQueries.MaxPageSize, false));

            AddResponse(query, response);
        }
Пример #7
0
        private void SetupQueriesOnNodeForImageConnections()
        {
            QueryRootQuery query = new QueryRootQuery();

            query.node(n => n
                       .onProduct(p => p
                                  .id()
                                  .images(ic => DefaultQueries.products.ImageConnection(ic),
                                          first: DefaultQueries.MaxPageSize, after: "image249"
                                          )
                                  ),
                       id: "1", alias: "a1"
                       );

            query.node(n => n
                       .onProduct(p => p
                                  .id()
                                  .images(ic => DefaultQueries.products.ImageConnection(ic),
                                          first: DefaultQueries.MaxPageSize, after: "image249"
                                          )
                                  .variants(
                                      vc => DefaultQueries.products.ProductVariantConnection(vc, ShopifyClient.DefaultImageResolutions),
                                      first: DefaultQueries.MaxPageSize, after: "variant249"
                                      )
                                  ),
                       id: "2", alias: "a2"
                       );

            string response = String.Format(@"{{
                ""data"": {{
                    ""node___a1"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""1"",
                        ""images"": {{
                            ""edges"": [
                                {0}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {1}
                            }}
                        }}
                    }},
                    ""node___a2"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""2"",
                        ""images"": {{
                            ""edges"": [
                                {2}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {3}
                            }}
                        }},
                        ""variants"": {{
                            ""edges"": [
                                {4}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {5}
                            }}
                        }}
                    }}
                }}
            }}", GetImageNodes(1, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(false), GetImageNodes(1, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(true), GetVariants(1, 2, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(false));

            AddResponse(query, response);

            query = new QueryRootQuery();
            query.node(n => n
                       .onProduct(p => p
                                  .id()
                                  .images(ic => DefaultQueries.products.ImageConnection(ic),
                                          first: DefaultQueries.MaxPageSize, after: "image499"
                                          )
                                  ),
                       id: "2", alias: "a2"
                       );

            response = String.Format(@"{{
                ""data"": {{
                    ""node___a2"": {{
                        ""__typename"": ""Product"",
                        ""id"": ""2"",
                        ""images"": {{
                            ""edges"": [
                                {0}
                            ],
                            ""pageInfo"": {{
                                ""hasNextPage"": {1}
                            }}
                        }}
                    }}
                }}
            }}", GetImageNodes(2, DefaultQueries.MaxPageSize), UtilsMockLoader.GetJSONBool(false));

            AddResponse(query, response);
        }
        public void SetupQueriesOnNodesForProducts()
        {
            QueryRootQuery query = new QueryRootQuery();

            List <string> productIds = new List <string>();

            productIds.Add("productId333");
            productIds.Add("productId444");

            query.nodes(n => n
                        .onProduct(p => DefaultQueries.products.Product(p, ShopifyClient.DefaultImageResolutions)),
                        ids: productIds
                        );

            string response = String.Format(@"{{
                ""data"": {{
                    ""nodes"": [
                        {{
                            ""__typename"": ""Product"",
                            ""id"": ""productId333"",
                            {0},
                            ""variants"": {{
                                ""edges"": [
                                    {2}
                                ],
                                ""pageInfo"": {{
                                    ""hasNextPage"": {3}
                                }}
                            }},
                            ""collections"": {{
                                ""edges"": [
                                    {{
                                        ""node"": {{
                                            ""id"": ""0"",
                                            ""title"": ""I am collection 0"",
                                            ""updatedAt"": ""2016-09-11T21:32:43Z""
                                        }},
                                        ""cursor"": ""0""
                                    }}
                                ],
                                ""pageInfo"": {{
                                    ""hasNextPage"": false
                                }}
                            }}
                        }},
                        {{
                            ""__typename"": ""Product"",
                            ""id"": ""productId444"",
                            {0},
                            ""variants"": {{
                                ""edges"": [
                                    {2}
                                ],
                                ""pageInfo"": {{
                                    ""hasNextPage"": {3}
                                }}
                            }},
                            ""collections"": {{
                                ""edges"": [
                                    {{
                                        ""node"": {{
                                            ""id"": ""0"",
                                            ""title"": ""I am collection 0"",
                                            ""updatedAt"": ""2016-09-11T21:32:43Z""
                                        }},
                                        ""cursor"": ""0""
                                    }}
                                ],
                                ""pageInfo"": {{
                                    ""hasNextPage"": false
                                }}
                            }}
                        }}
                    ]
                }}
            }}", GetImagesConnection(0, 1, true), GetImagesConnection(0, 1, false), GetVariants(1, 2, 1), UtilsMockLoader.GetJSONBool(false));

            AddResponse(query, response);
        }