Esempio n. 1
0
        public void GetCategoryById()
        {
            IClient commerceToolsClient = this.graphqlFixture.GetService <IClient>();
            var     category            = this.graphqlFixture.CreateCategory();


            var query = new GraphQLParameters(
                @"query Sphere($cid: String!) {
                    categories(where: $cid) {
                        results {
                            id
                        }
                    }
                }",
                new Dictionary <string, object>()
            {
                { "cid", $"id = \"{category.Id}\"" }
            }
                );
            var graphQlCommand = new GraphQLCommand <dynamic>(query);

            var result = commerceToolsClient.ExecuteAsync(graphQlCommand).Result;

            Assert.Equal(category.Id, result.data.categories.results[0].id.Value);
        }
Esempio n. 2
0
        public async Task UpdateAnOrder()
        {
            //Arrange
            var orderNumber = $"order-{TestingUtility.RandomInt()}";
            var query       = @"mutation ($orderId:String, $orderNumber:String){
                                updateOrder(
                                             version: 1,
                                             id:$orderId,
                                             actions: [
                                                        {
                                                            changeOrderState:{
                                                              orderState: Confirmed
                                                            }
                                                        },
                                                        {
                                                            setOrderNumber:{
                                                              orderNumber: $orderNumber
                                                            }
                                                        }
                                                      ]
                                            ) {
                                                id,
                                                orderNumber,
                                                orderState,
                                                version
                                              } 
                                    }";

            //act
            await WithCartWithSingleLineItem(client, 2, DefaultCartDraft,
                                             async cart =>
            {
                Assert.Single(cart.LineItems);

                //create order with null orderNumber
                await WithUpdateableOrder(client,
                                          draft => DefaultOrderFromCartDraftWithNumber(draft, cart, orderNumber: null),
                                          async order =>
                {
                    Assert.NotNull(order);
                    Assert.Null(order.OrderNumber);

                    var queryParameters = new GraphQLParameters(query, new Dictionary <string, object>
                    {
                        { "orderId", order.Id },
                        { "orderNumber", orderNumber }
                    });
                    var graphQlCommand      = new GraphQLCommand <dynamic>(queryParameters);
                    var result              = await client.ExecuteAsync(graphQlCommand);
                    var updatedOrderJObject = result.data.updateOrder as JObject;
                    Assert.NotNull(updatedOrderJObject);
                    var updatedOrder = updatedOrderJObject.ToObject <Order>();
                    Assert.Equal(order.Id, updatedOrder.Id);
                    Assert.Equal(OrderState.Confirmed, updatedOrder.OrderState);
                    Assert.Equal(orderNumber, updatedOrder.OrderNumber);
                    return(updatedOrder);
                });
            });
        }
 public async Task CreateCustomerGroup()
 {
     await WithCategory(client, async category =>
     {
         var query           = @"query Test($cid: String!) {
             categories(where: $cid) {
                 results {
                     id
                 }
             }
         }";
         var queryParameters = new GraphQLParameters(query, new Dictionary <string, object>
         {
             { "cid", $"id = \"{category.Id}\"" }
         });
         var graphQlCommand = new GraphQLCommand <dynamic>(queryParameters);
         var result         = await client.ExecuteAsync(graphQlCommand);
         Assert.Equal(category.Id, result.data.categories.results[0].id.Value);
     });
 }