public async Task ShouldCreateAndDeleteCartAsync()
        {
            CartDraft cartDraft = Helper.GetTestCartDraft(_project);

            Response <Cart> response = await _client.Carts().CreateCartAsync(cartDraft);

            Assert.True(response.Success);

            Cart cart = response.Result;

            Assert.NotNull(cart.Id);
            Assert.Equal(cart.Country, cartDraft.Country);
            Assert.Equal(cart.InventoryMode, cartDraft.InventoryMode);
            Assert.Equal(cart.ShippingAddress, cartDraft.ShippingAddress);
            Assert.Equal(cart.BillingAddress, cartDraft.BillingAddress);
            Assert.Equal(cartDraft.DeleteDaysAfterLastModification, cart.DeleteDaysAfterLastModification);

            string deletedCartId = cart.Id;

            response = await _client.Carts().DeleteCartAsync(cart);

            Assert.True(response.Success);

            cart = response.Result;

            response = await _client.Carts().GetCartByIdAsync(deletedCartId);

            Assert.False(response.Success);
        }
        public async Task ShouldCreateAndDeleteCartWithCustomLineItemsAsync()
        {
            CartDraft       cartDraft = Helper.GetTestCartDraftWithCustomLineItems(_project);
            Response <Cart> response  = await _client.Carts().CreateCartAsync(cartDraft);

            Assert.IsTrue(response.Success);

            Cart cart = response.Result;

            Assert.NotNull(cart.Id);

            Assert.AreEqual(cart.Country, cartDraft.Country);
            Assert.AreEqual(cart.InventoryMode, cartDraft.InventoryMode);
            Assert.AreEqual(cart.ShippingAddress, cartDraft.ShippingAddress);
            Assert.AreEqual(cart.BillingAddress, cartDraft.BillingAddress);

            string deletedCartId = cart.Id;

            response = await _client.Carts().DeleteCartAsync(cart);

            Assert.IsTrue(response.Success);

            cart = response.Result;

            response = await _client.Carts().GetCartByIdAsync(deletedCartId);

            Assert.IsFalse(response.Success);
        }
Beispiel #3
0
        public CartDraft GetCartDraft(bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false)
        {
            string country = withDefaultShippingCountry ? "DE" : this.GetRandomEuropeCountry();

            var address = new Address {
                Country = country, Key = this.RandomString(10)
            };

            CartDraft cartDraft = new CartDraft();

            cartDraft.Currency        = "EUR";
            cartDraft.ShippingAddress = address;
            cartDraft.DeleteDaysAfterLastModification = 1;

            if (withItemShippingAddress)
            {
                cartDraft.ItemShippingAddresses = new List <Address> {
                    address
                };
            }
            if (withCustomer)//then create customer and attach it to the cart
            {
                Customer customer = this.customerFixture.CreateCustomer();
                this.customerFixture.CustomersToDelete.Add(customer);
                cartDraft.CustomerId = customer.Id;
            }
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraftWithTaxRoundingMode(CartDraft draft, RoundingMode roundingMode)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.TaxRoundingMode = roundingMode;
            return(cartDraft);
        }
        public async Task ShouldApplyDiscountOnCartWithCustomLineItemsAsync()
        {
            // Arrange
            CartDiscount cartDiscount = await Helper.CreateCartDiscountForCustomLineItems(this._project, this._client);

            CartDraft cartDraft = Helper.GetTestCartDraftWithCustomLineItems(_project);

            // Act
            Response <Cart> response = await _client.Carts().CreateCartAsync(cartDraft);

            // Assert
            response.Result.CustomLineItems.Count.Should().Be(1);
            var customLineItem = response.Result.CustomLineItems.First();

            customLineItem.DiscountedPricePerQuantity.Count.Should().BeGreaterThan(0);
            var discountedLineItemPrice = customLineItem.DiscountedPricePerQuantity.First();

            discountedLineItemPrice.DiscountedPrice.Value.CentAmount.Should().BeGreaterThan(1);
            discountedLineItemPrice.DiscountedPrice.Value.CurrencyCode.Should().Be("EUR");
            Assert.NotNull(discountedLineItemPrice);
            Assert.NotNull(discountedLineItemPrice.DiscountedPrice);
            Assert.NotNull(discountedLineItemPrice.DiscountedPrice.Value);
            Assert.NotNull(discountedLineItemPrice.DiscountedPrice.Value);
            Assert.IsFalse(string.IsNullOrEmpty(discountedLineItemPrice.DiscountedPrice.Value.CurrencyCode));

            // Cleanup
            await this._client.CartDiscounts().DeleteCartDiscountAsync(cartDiscount.Id, 1);

            await this._client.Carts().DeleteCartAsync(response.Result);
        }
        public static CartDraft DefaultCartDraftWithTaxMode(CartDraft draft, TaxMode taxMode)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.TaxMode = taxMode;
            return(cartDraft);
        }
        public Cart CreateCart(CartDraft cartDraft)
        {
            IClient commerceToolsClient = this.GetService <IClient>();
            Cart    cart = commerceToolsClient.ExecuteAsync(new CreateCommand <Cart>(cartDraft)).Result;

            return(cart);
        }
        public Cart CreateCart(TaxMode taxMode = TaxMode.Platform, bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false)
        {
            CartDraft cartDraft = this.GetCartDraft(withCustomer, withDefaultShippingCountry, withItemShippingAddress);

            cartDraft.TaxMode = taxMode;
            return(this.CreateCart(cartDraft));
        }
        public static CartDraft DefaultCartDraftWithShippingMethod(CartDraft draft, ShippingMethod shippingMethod)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.ShippingMethod = shippingMethod.ToReference();
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraftWithShippingAddress(CartDraft draft, Address address)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.ShippingAddress = address;
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraftWithKey(CartDraft draft, string key)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.Key = key;
            return(cartDraft);
        }
Beispiel #12
0
        public void Init()
        {
            _client = Helper.GetClient();



            Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync();

            projectTask.Wait();
            Assert.IsTrue(projectTask.Result.Success);
            _project = projectTask.Result.Result;

            CustomerDraft customerDraft = Helper.GetTestCustomerDraft();
            Task <Response <CustomerCreatedMessage> > customerTask = _client.Customers().CreateCustomerAsync(customerDraft);

            customerTask.Wait();
            Assert.IsTrue(customerTask.Result.Success);

            CustomerCreatedMessage customerCreatedMessage = customerTask.Result.Result;

            Assert.NotNull(customerCreatedMessage.Customer);
            Assert.NotNull(customerCreatedMessage.Customer.Id);

            _testCustomer = customerCreatedMessage.Customer;

            CartDraft cartDraft = Helper.GetTestCartDraft(_project, _testCustomer.Id);
            Task <Response <Cart> > cartTask = _client.Carts().CreateCartAsync(cartDraft);

            cartTask.Wait();
            Assert.IsTrue(cartTask.Result.Success);

            _testCart = cartTask.Result.Result;
            Assert.NotNull(_testCart.Id);
            Assert.AreEqual(_testCart.CustomerId, _testCustomer.Id);
        }
        public static CartDraft DefaultCartDraftWithCustomer(CartDraft draft, Customer customer)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.CustomerId    = customer.Id;
            cartDraft.CustomerEmail = customer.Email;
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraftWithItemShippingAddresses(CartDraft draft,
                                                                          List <Address> itemShippingAddresses)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.ItemShippingAddresses = itemShippingAddresses;
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraft(CartDraft cartDraft)
        {
            var randomInt = TestingUtility.RandomInt();

            cartDraft.Currency = DefaultCurrency;
            cartDraft.Key      = $"Key{randomInt}";
            return(cartDraft);
        }
        public static CartDraft DefaultCartDraftWithLineItem(CartDraft draft, LineItemDraft lineItemDraft)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.LineItems = new List <LineItemDraft> {
                lineItemDraft
            };
            return(cartDraft);
        }
Beispiel #17
0
        public async Task ShouldCreateOrderFromCartAndDeleteOrderAsync()
        {
            CartDraft       cartDraft    = Helper.GetTestCartDraft(_project, _testCustomers[0].Id);
            Response <Cart> cartResponse = await _client.Carts().CreateCartAsync(cartDraft);

            Assert.IsTrue(cartResponse.Success);

            Cart cart = cartResponse.Result;

            Assert.NotNull(cart.Id);

            int quantity = 3;
            AddLineItemAction addLineItemAction = new AddLineItemAction(_testProduct.Id, _testProduct.MasterData.Current.MasterVariant.Id);

            addLineItemAction.Quantity = quantity;
            cartResponse = await _client.Carts().UpdateCartAsync(cart, addLineItemAction);

            Assert.IsTrue(cartResponse.Success);

            cart = cartResponse.Result;
            Assert.NotNull(cart.Id);
            Assert.NotNull(cart.LineItems);
            Assert.AreEqual(cart.LineItems.Count, 1);
            Assert.AreEqual(cart.LineItems[0].ProductId, _testProduct.Id);
            Assert.AreEqual(cart.LineItems[0].Variant.Id, _testProduct.MasterData.Current.MasterVariant.Id);
            Assert.AreEqual(cart.LineItems[0].Quantity, quantity);

            OrderFromCartDraft orderFromCartDraft = Helper.GetTestOrderFromCartDraft(cart);
            Response <Order>   orderResponse      = await _client.Orders().CreateOrderFromCartAsync(orderFromCartDraft);

            Assert.IsTrue(orderResponse.Success);

            Order order = orderResponse.Result;

            Assert.NotNull(order.Id);

            // To get the new version number.
            cartResponse = await _client.Carts().GetCartByIdAsync(cart.Id);

            Assert.IsTrue(cartResponse.Success);
            cart = cartResponse.Result;

            string deletedOrderId = order.Id;

            Response <JObject> response = await _client.Orders().DeleteOrderAsync(order);

            Assert.IsTrue(response.Success);

            orderResponse = await _client.Orders().GetOrderByIdAsync(deletedOrderId);

            Assert.IsFalse(orderResponse.Success);

            await _client.Carts().DeleteCartAsync(cart);
        }
        public static CartDraft DefaultCartDraftWithCustomLineItem(CartDraft draft,
                                                                   CustomLineItemDraft customLineItemDraft)
        {
            var cartDraft = DefaultCartDraft(draft);

            cartDraft.CustomLineItems = new List <CustomLineItemDraft>
            {
                customLineItemDraft
            };
            return(cartDraft);
        }
        public void SerializeReviewDraftInvalidCurrency()
        {
            ISerializerService serializerService = this.serializationFixture.SerializerService;
            CartDraft          cartDraft         = new CartDraft()
            {
                Currency = "ZZZ"
            };
            ValidationException exception = Assert.Throws <ValidationException>(() => serializerService.Serialize(cartDraft));

            Assert.Single(exception.Errors);
        }
        public Cart CreateCartWithCustomLineItem(bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false, bool withShippingMethod = false, string customerEmail = null)
        {
            var       customLineItemDraft = this.GetCustomLineItemDraft();
            CartDraft cartDraft           = this.GetCartDraft(withCustomer, withDefaultShippingCountry, withItemShippingAddress, withShippingMethod, customerEmail);

            cartDraft.CustomLineItems = new List <CustomLineItemDraft> {
                customLineItemDraft
            };
            Cart cart = this.CreateCart(cartDraft);

            return(cart);
        }
        public Cart CreateCartWithCustomLineItemWithSpecificTaxMode(TaxMode taxMode, bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false)
        {
            var       customLineItemDraft = this.GetCustomLineItemDraft();
            CartDraft cartDraft           = this.GetCartDraft(withCustomer, withDefaultShippingCountry, withItemShippingAddress);

            cartDraft.CustomLineItems = new List <CustomLineItemDraft> {
                customLineItemDraft
            };
            cartDraft.TaxMode = taxMode;
            Cart cart = this.CreateCart(cartDraft);

            return(cart);
        }
        public static CartDraft DefaultCartDraftWithCustomType(CartDraft draft, Type type, Fields fields)
        {
            var customFieldsDraft = new CustomFieldsDraft
            {
                Type   = type.ToKeyResourceIdentifier(),
                Fields = fields
            };

            var cartDraft = DefaultCartDraft(draft);

            cartDraft.Custom = customFieldsDraft;

            return(cartDraft);
        }
Beispiel #23
0
        public Cart CreateCartWithLineItem(TaxMode taxMode = TaxMode.Platform, bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false)
        {
            Product       product       = this.CreateProduct();
            LineItemDraft lineItemDraft = this.GetLineItemDraftBySku(product.MasterData.Current.MasterVariant.Sku, quantity: 6);
            CartDraft     cartDraft     = this.GetCartDraft(withCustomer, withDefaultShippingCountry, withItemShippingAddress);

            cartDraft.LineItems = new List <LineItemDraft> {
                lineItemDraft
            };
            cartDraft.TaxMode = taxMode;
            Cart cart = this.CreateCart(cartDraft);

            return(cart);
        }
        public Cart CreateCartWithLineItem(TaxMode taxMode = TaxMode.Platform, bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false, bool withShippingMethod = false, string customerEmail = null)
        {
            CartDraft cartDraft = this.GetCartDraft(withCustomer, withDefaultShippingCountry, withItemShippingAddress, withShippingMethod, customerEmail);

            var taxCategoryReference = withShippingMethod
                ? this.shippingMethodsFixture.GetShippingMethodTaxCategoryByKey(cartDraft.ShippingMethod.Key)
                : null;
            Product       product       = this.CreateProduct(taxCategoryReference: taxCategoryReference);
            LineItemDraft lineItemDraft = this.GetLineItemDraftBySku(product.MasterData.Current.MasterVariant.Sku, quantity: 6);

            cartDraft.LineItems = new List <LineItemDraft> {
                lineItemDraft
            };
            cartDraft.TaxMode = taxMode;
            Cart cart = this.CreateCart(cartDraft);

            return(cart);
        }
Beispiel #25
0
        /// <summary>
        /// Gets a test cart draft.
        /// </summary>
        /// <param name="project">Project</param>
        /// <param name="customerId">Customer ID</param>
        /// <returns>CartDraft</returns>
        public static CartDraft GetTestCartDraft(Project.Project project, string customerId = null)
        {
            Address shippingAddress = Helper.GetTestAddress(project);
            Address billingAddress  = Helper.GetTestAddress(project);

            string currency = project.Currencies[0];
            string country  = project.Countries[0];

            CartDraft cartDraft = new CartDraft(currency);

            cartDraft.Country         = country;
            cartDraft.InventoryMode   = InventoryMode.None;
            cartDraft.ShippingAddress = shippingAddress;
            cartDraft.BillingAddress  = billingAddress;
            cartDraft.DeleteDaysAfterLastModification = GetRandomNumber(1, 10);
            if (!string.IsNullOrWhiteSpace(customerId))
            {
                cartDraft.CustomerId = customerId;
            }
            return(cartDraft);
        }
Beispiel #26
0
        public void IsCreateCommandInStore()
        {
            var builder   = new CommandBuilder();
            var cartDraft = new CartDraft
            {
                Currency = "EUR"
            };
            var command = builder
                          .Carts()
                          .InStore("storeKey")
                          .Create(cartDraft)
                          .Build();

            Assert.NotNull(command);
            Assert.Equal("storeKey", command.StoreKey);
            var innerCommand      = command.InnerCommand;
            var createCartCommand = innerCommand as CreateCommand <Cart>;

            Assert.NotNull(createCartCommand);
            Assert.NotNull(createCartCommand.Entity);
        }
        /// <summary>
        /// Gets a test cart draft with custom line items using external tax mode.
        /// </summary>
        /// <param name="project">Project</param>
        /// <param name="customerId">Customer ID</param>
        /// <returns>CartDraft</returns>
        public static CartDraft GetTestCartDraftWithCustomLineItemsUsingExternalTaxMode(Project.Project project, string customerId = null)
        {
            var shippingAddress = GetTestAddress(project);
            var billingAddress  = GetTestAddress(project);
            var name            = new LocalizedString();

            name.Values.Add("en", "Test-CustomLineItem");
            var currency = project.Currencies[0];
            var country  = project.Countries[0];

            var cartDraft = new CartDraft(currency)
            {
                Country         = country,
                InventoryMode   = InventoryMode.None,
                ShippingAddress = shippingAddress,
                BillingAddress  = billingAddress,
                TaxMode         = TaxMode.External,
                CustomLineItems = new List <CustomLineItemDraft>()
            };

            if (!string.IsNullOrWhiteSpace(customerId))
            {
                cartDraft.CustomerId = customerId;
            }
            cartDraft.CustomLineItems.Add(new CustomLineItemDraft(name)
            {
                Quantity = 40,
                Money    = new Money
                {
                    CentAmount   = 30,
                    CurrencyCode = currency
                },
                Slug            = "Test-CustomLineItem-Slug",
                ExternalTaxRate = new ExternalTaxRateDraft("TestExternalTaxRate", project.Countries[0])
                {
                    Amount = 0
                }
            });
            return(cartDraft);
        }
        public CartDraft GetCartDraft(bool withCustomer = true, bool withDefaultShippingCountry = true, bool withItemShippingAddress = false, bool withShippingMethod = false, string customerEmail = null)
        {
            string country = withDefaultShippingCountry ? "DE" : TestingUtility.GetRandomEuropeCountry();
            string state   = withDefaultShippingCountry ? null : $"{country}_State_{TestingUtility.RandomInt()}";
            var    address = new Address {
                Country = country, State = state, Key = TestingUtility.RandomString(10)
            };

            CartDraft cartDraft = new CartDraft();

            cartDraft.Currency        = "EUR";
            cartDraft.ShippingAddress = address;
            cartDraft.DeleteDaysAfterLastModification = 1;

            if (withItemShippingAddress)
            {
                cartDraft.ItemShippingAddresses = new List <Address> {
                    address
                };
            }
            if (withCustomer)//then create customer and attach it to the cart
            {
                Customer customer = this.customerFixture.CreateCustomer();
                this.customerFixture.CustomersToDelete.Add(customer);
                cartDraft.CustomerId    = customer.Id;
                cartDraft.CustomerEmail = customerEmail;
            }

            if (withShippingMethod)
            {
                var shippingMethod = this.shippingMethodsFixture.CreateShippingMethod(country, state);
                this.shippingMethodsFixture.ShippingMethodsToDelete.Add(shippingMethod);
                cartDraft.ShippingMethod = new ResourceIdentifier <ShippingMethod>
                {
                    Key = shippingMethod.Key
                };
            }
            return(cartDraft);
        }
        /// <summary>
        /// Gets a test cart draft using external tax mode.
        /// </summary>
        /// <param name="project">Project</param>
        /// <param name="customerId">Customer ID</param>
        /// <returns>CartDraft</returns>
        public static CartDraft GetTestCartDraftUsingExternalTaxMode(Project.Project project, string customerId = null)
        {
            Address shippingAddress = Helper.GetTestAddress(project);
            Address billingAddress  = Helper.GetTestAddress(project);

            string currency = project.Currencies[0];
            string country  = project.Countries[0];

            CartDraft cartDraft = new CartDraft(currency);

            cartDraft.Country         = country;
            cartDraft.InventoryMode   = InventoryMode.None;
            cartDraft.ShippingAddress = shippingAddress;
            cartDraft.BillingAddress  = billingAddress;
            cartDraft.TaxMode         = TaxMode.External;

            if (!string.IsNullOrWhiteSpace(customerId))
            {
                cartDraft.CustomerId = customerId;
            }
            return(cartDraft);
        }
Beispiel #30
0
        /// <summary>
        /// Gets a test cart draft with custom line items.
        /// </summary>
        /// <param name="project">Project</param>
        /// <param name="customerId">Customer ID</param>
        /// <returns>CartDraft</returns>
        public static CartDraft GetTestCartDraftWithCustomLineItems(Project.Project project, string customerId = null)
        {
            var shippingAddress = GetTestAddress(project);
            var billingAddress  = GetTestAddress(project);
            var name            = new LocalizedString();

            name.Values.Add("en", "Test-CustomLineItem");
            var currency = project.Currencies[0];
            var country  = project.Countries[0];

            var cartDraft = new CartDraft(currency)
            {
                Country         = country,
                InventoryMode   = InventoryMode.None,
                ShippingAddress = shippingAddress,
                BillingAddress  = billingAddress,
                TaxMode         = TaxMode.Disabled,
                CustomLineItems = new List <CustomLineItemDraft>()
            };

            cartDraft.DeleteDaysAfterLastModification = GetRandomNumber(1, 10);

            if (!string.IsNullOrWhiteSpace(customerId))
            {
                cartDraft.CustomerId = customerId;
            }
            cartDraft.CustomLineItems.Add(new CustomLineItemDraft(name)
            {
                Quantity = 40,
                Money    = new Money
                {
                    CentAmount   = 30,
                    CurrencyCode = currency
                },
                Slug = "Test-CustomLineItem-Slug",
            });
            return(cartDraft);
        }