public async void UpdateShoppingListInStoreSetChangeKey()
        {
            var newKey = $"UpdateShoppingListSetKey-{TestingUtility.RandomString()}";

            await WithStore(client, async store =>
            {
                await WithUpdateableShoppingList(client,
                                                 draft => DefaultShoppingListDraftInStore(DefaultShoppingListDraft(draft),
                                                                                          store.ToKeyResourceIdentifier()),
                                                 async shoppingList =>
                {
                    Assert.NotNull(shoppingList.Store);
                    Assert.Equal(store.Key, shoppingList.Store.Key);
                    var action = new SetKeyUpdateAction
                    {
                        Key = newKey
                    };

                    var updatedShoppingList = await client
                                              .ExecuteAsync(shoppingList.UpdateById(
                                                                actions => actions.AddUpdate(action)).InStore(store.Key));

                    Assert.NotNull(updatedShoppingList.Store);
                    Assert.Equal(store.Key, updatedShoppingList.Store.Key);
                    Assert.Equal(newKey, updatedShoppingList.Key);
                    return(updatedShoppingList);
                });
            });
        }
        public static async Task WithListOfCartsWithSingleLineItem(IClient client, int cartsCount, int lineItemQuantity,
                                                                   Func <CartDraft, CartDraft> draftAction, Func <List <Cart>, Task> func)
        {
            var address      = TestingUtility.GetRandomAddress();
            var taxRateDraft = TestingUtility.GetTaxRateDraft(address);

            await WithTaxCategory(client, draft =>
                                  DefaultTaxCategoryDraftWithTaxRate(draft, taxRateDraft),
                                  async taxCategory =>
            {
                await WithProduct(client,
                                  productDraft =>
                                  DefaultProductDraftWithTaxCategory(productDraft, taxCategory),
                                  async product =>
                {
                    var lineItemDraft = new LineItemDraft
                    {
                        Sku      = product.MasterData.Staged.MasterVariant.Sku,
                        Quantity = lineItemQuantity
                    };
                    var cartDraft = DefaultCartDraftWithShippingAddress(new CartDraft(), address);
                    cartDraft     = DefaultCartDraftWithLineItem(cartDraft, lineItemDraft);

                    await WithListAsync(client, cartDraft, draftAction, func, cartsCount);
                });
            });
        }
Ejemplo n.º 3
0
        public OrderFromCartDraft GetOrderFromCartDraft(bool withDefaultShippingCountry = true, bool withShippingMethod = false, bool withOrderNumber = true, bool withCustomer = true, bool withCustomLineItem = false, bool withItemShippingAddress = false, string customerEmail = null)
        {
            //Create A Cart
            Cart cart = null;

            if (withCustomLineItem)
            {
                cart = this.cartFixture.CreateCartWithCustomLineItem(
                    withDefaultShippingCountry: withDefaultShippingCountry,
                    withCustomer: withCustomer, withItemShippingAddress: withItemShippingAddress, customerEmail: customerEmail);
            }
            else
            {
                cart = this.cartFixture.CreateCartWithLineItem(withDefaultShippingCountry: withDefaultShippingCountry,
                                                               withShippingMethod: withShippingMethod, withCustomer: withCustomer,
                                                               withItemShippingAddress: withItemShippingAddress, customerEmail: customerEmail);
            }

            //Then Create Order from this Cart
            OrderFromCartDraft orderFromCartDraft = new OrderFromCartDraft
            {
                Id      = cart.Id,
                Version = cart.Version
            };

            if (withOrderNumber)
            {
                orderFromCartDraft.OrderNumber = TestingUtility.RandomString(10);
            }

            return(orderFromCartDraft);
        }
        public async void CheckConcurrentModificationException()
        {
            await WithUpdateableCategory(client, async category =>
            {
                var key    = TestingUtility.RandomString();
                var action = new SetKeyUpdateAction {
                    Key = key
                };

                var updatedCategory = await client
                                      .ExecuteAsync(category.UpdateById(actions => actions.AddUpdate(action)));

                Assert.Equal(key, updatedCategory.Key);

                // updatedCategory now has a new version
                // then if we try to update the original category it will throw ConCurrentModification Exception

                var exception = await Assert.ThrowsAsync <ConcurrentModificationException>(() =>
                                                                                           client.ExecuteAsync(
                                                                                               category.UpdateById(actions => actions.AddUpdate(action))));

                Assert.NotNull(exception);
                Assert.Single(exception.ErrorResponse.Errors);
                Assert.IsType <ConcurrentModificationError>(exception.ErrorResponse.Errors[0]);
                Assert.Equal(exception.GetCurrentVersion(), updatedCategory.Version);
                return(updatedCategory);
            });
        }
Ejemplo n.º 5
0
 public static TypeDraft DefaultTypeDraft(TypeDraft typeDraft)
 {
     typeDraft.Key  = TestingUtility.RandomString(10);
     typeDraft.Name = new LocalizedString();
     typeDraft.Name.Add("en", TestingUtility.RandomString(10));
     typeDraft.Description = new LocalizedString();
     typeDraft.Description.Add("en", TestingUtility.RandomString(10));
     typeDraft.ResourceTypeIds = new List <ResourceTypeId>()
     {
         ResourceTypeId.Category, ResourceTypeId.CustomerGroup, ResourceTypeId.InventoryEntry, ResourceTypeId.Order, ResourceTypeId.LineItem, ResourceTypeId.CustomLineItem, ResourceTypeId.ProductPrice, ResourceTypeId.Asset, ResourceTypeId.Payment, ResourceTypeId.PaymentInterfaceInteraction, ResourceTypeId.Review, ResourceTypeId.CartDiscount, ResourceTypeId.DiscountCode, ResourceTypeId.Channel, ResourceTypeId.ShoppingList, ResourceTypeId.ShoppingListTextLineItem
     };
     typeDraft.FieldDefinitions = new List <FieldDefinition>();
     typeDraft.FieldDefinitions.Add(CreateStringFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateLocalizedStringFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateNumberFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateBooleanFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateEnumFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateLocalizedEnumFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateMoneyFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateDateFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateTimeFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateDateTimeFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateReferenceFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateCustomObjectReferenceFieldDefinition());
     typeDraft.FieldDefinitions.Add(CreateSetFieldDefinition());
     return(typeDraft);
 }
        public async Task UpdateReviewSetCustomField()
        {
            var fields   = CreateNewFields();
            var newValue = TestingUtility.RandomString(10);

            await WithType(client, async type =>
            {
                await WithUpdateableReview(client,
                                           reviewDraft => DefaultReviewDraftWithCustomType(reviewDraft, type, fields),
                                           async review =>
                {
                    Assert.Equal(type.Id, review.Custom.Type.Id);

                    var updateActions = new List <UpdateAction <Review> >();
                    var setCustomFieldUpdateAction = new SetCustomFieldUpdateAction()
                    {
                        Name = "string-field", Value = newValue
                    };
                    updateActions.Add(setCustomFieldUpdateAction);

                    var updatedReview = await client.ExecuteAsync(new UpdateByIdCommand <Review>(review, updateActions));

                    Assert.Equal(newValue, updatedReview.Custom.Fields["string-field"]);
                    return(updatedReview);
                });
            });
        }
        public async Task AuthenticateWithInvalidCustomerPassword()
        {
            var containerType = Enum.Parse <ContainerType>(configuration.GetValue <string>("Container"));

            if (containerType != ContainerType.BuiltIn)
            {
                return;
            }
            var password        = TestingUtility.RandomString();
            var invalidPassword = "******";

            await WithCustomer(
                client,
                customerDraft => DefaultCustomerDraftWithPassword(customerDraft, password),
                async customer =>
            {
                try
                {
                    await client.ExecuteAsync(
                        new LoginCustomerCommand(customer.Email, invalidPassword));
                }
                catch (Exception ex)
                {
                    Assert.IsType <ErrorResponseException>(ex);
                    Assert.DoesNotContain(ex.Message, invalidPassword);
                    Assert.DoesNotContain(ex.StackTrace, invalidPassword);
                }

                var log = InMemoryLogger.GetLogMessages();
                Assert.NotEmpty(log);
                Assert.DoesNotContain(log, invalidPassword);
            });
        }
        public async Task UpdateReviewSetCustomer()
        {
            var key = $"UpdateReviewSetCustomer-{TestingUtility.RandomString()}";

            await WithCustomer(client, async customer =>
            {
                await WithUpdateableReview(client, reviewDraft => DefaultReviewDraftWithKey(reviewDraft, key),
                                           async review =>
                {
                    var updateActions     = new List <UpdateAction <Review> >();
                    var setCustomerAction = new SetCustomerUpdateAction
                    {
                        Customer = customer.ToKeyResourceIdentifier()
                    };
                    updateActions.Add(setCustomerAction);
                    var updateCommand = new UpdateByKeyCommand <Review>(key, review.Version, updateActions);
                    updateCommand.Expand(r => r.Customer);

                    var updatedReview = await client.ExecuteAsync(updateCommand);

                    Assert.NotNull(updatedReview.Customer.Obj);
                    Assert.Equal(customer.Key, updatedReview.Customer.Obj.Key);
                    return(updatedReview);
                });
            });
        }
Ejemplo n.º 9
0
        public void UpdateCartDiscountByIdSetDescription()
        {
            IClient      commerceToolsClient = this.cartDiscountFixture.GetService <IClient>();
            CartDiscount cartDiscount        = this.cartDiscountFixture.CreateCartDiscount();

            string newDescription = TestingUtility.RandomString(20);
            List <UpdateAction <CartDiscount> > updateActions = new List <UpdateAction <CartDiscount> >();
            SetDescriptionUpdateAction          setDescriptionUpdateAction = new SetDescriptionUpdateAction()
            {
                Description = new LocalizedString()
                {
                    { "en", newDescription }
                }
            };

            updateActions.Add(setDescriptionUpdateAction);

            CartDiscount retrievedCartDiscount = commerceToolsClient
                                                 .ExecuteAsync(new UpdateByIdCommand <CartDiscount>(new Guid(cartDiscount.Id), cartDiscount.Version,
                                                                                                    updateActions))
                                                 .Result;

            this.cartDiscountFixture.CartDiscountsToDelete.Add(retrievedCartDiscount);
            Assert.Equal(newDescription, retrievedCartDiscount.Description["en"]);
        }
Ejemplo n.º 10
0
        public void UpdateCartDiscountByIdChangeName()
        {
            IClient      commerceToolsClient = this.cartDiscountFixture.GetService <IClient>();
            CartDiscount cartDiscount        = this.cartDiscountFixture.CreateCartDiscount();

            string name = TestingUtility.RandomString(10);
            List <UpdateAction <CartDiscount> > updateActions = new List <UpdateAction <CartDiscount> >();
            ChangeNameUpdateAction changeNameUpdateAction     = new ChangeNameUpdateAction()
            {
                Name = new LocalizedString()
                {
                    { "en", name }
                }
            };

            updateActions.Add(changeNameUpdateAction);

            CartDiscount retrievedCartDiscount = commerceToolsClient
                                                 .ExecuteAsync(new UpdateByIdCommand <CartDiscount>(new Guid(cartDiscount.Id), cartDiscount.Version,
                                                                                                    updateActions))
                                                 .Result;

            this.cartDiscountFixture.CartDiscountsToDelete.Add(retrievedCartDiscount);
            Assert.Equal(name, retrievedCartDiscount.Name["en"]);
        }
        public async Task UpdateProductTypeSetAttributeDefinitionInputTip()
        {
            var newInputTip = $"InputTip-{TestingUtility.RandomInt()}";

            await WithUpdateableProductType(client, DefaultProductTypeDraftWithOnlyTextAttribute,
                                            async productType =>
            {
                Assert.Single(productType.Attributes);
                var textAttribute     = productType.Attributes[0];
                var updateActions     = new List <UpdateAction <ProductType> >();
                var setInputTipAction = new SetAttributeDefinitionInputTipUpdateAction
                {
                    AttributeName = textAttribute.Name,
                    InputTip      = new LocalizedString {
                        { "en", newInputTip }
                    }
                };
                updateActions.Add(setInputTipAction);

                var updatedProductType = await client
                                         .ExecuteAsync(new UpdateByIdCommand <ProductType>(productType, updateActions));

                Assert.Equal(newInputTip, updatedProductType.Attributes[0].InputTip["en"]);
                return(updatedProductType);
            });
        }
        public async Task UpdateProductTypeChangeAttributeDefinitionLabel()
        {
            var newLabel = $"UpdateProductTypeChangeAttributeDefinitionLabel-{TestingUtility.RandomString()}";

            await WithUpdateableProductType(client, DefaultProductTypeDraftWithOnlyTextAttribute,
                                            async productType =>
            {
                Assert.Single(productType.Attributes);
                var textAttribute = productType.Attributes[0];
                var updateActions = new List <UpdateAction <ProductType> >();
                var changeAttributeLabelAction = new ChangeAttributeDefinitionLabelUpdateAction
                {
                    AttributeName = textAttribute.Name,
                    Label         = new LocalizedString {
                        { "en", newLabel }
                    }
                };
                updateActions.Add(changeAttributeLabelAction);

                var updatedProductType = await client
                                         .ExecuteAsync(new UpdateByIdCommand <ProductType>(productType, updateActions));

                Assert.Equal(newLabel, updatedProductType.Attributes[0].Label["en"]);
                return(updatedProductType);
            });
        }