예제 #1
0
        public void Init()
        {
            _client = new Client(Helper.GetConfiguration());

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

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

            _testInventories = new List <InventoryEntry>();

            for (int i = 0; i < 5; i++)
            {
                InventoryEntryDraft inventoryDraft = Helper.GetTestInventoryDraft(_project);

                Task <Response <InventoryEntry> > inventoryTask = _client.Inventories().CreateInventoryEntryAsync(inventoryDraft);
                inventoryTask.Wait();
                Assert.IsTrue(inventoryTask.Result.Success);

                InventoryEntry inventory = inventoryTask.Result.Result;
                Assert.NotNull(inventory.Id);

                _testInventories.Add(inventory);
            }
        }
예제 #2
0
        public static InventoryEntryDraft DefaultInventoryEntryDraftWithSku(InventoryEntryDraft draft, string sku)
        {
            var inventoryEntryDraft = DefaultInventoryEntryDraft(draft);

            inventoryEntryDraft.Sku = sku;
            return(inventoryEntryDraft);
        }
예제 #3
0
        public InventoryEntry CreateInventoryEntry(InventoryEntryDraft draft)
        {
            var inventoryEntry = this.inventoryFixture.CreateInventoryEntry(draft);

            this.inventoryFixture.InventoryEntries.Add(inventoryEntry);
            return(inventoryEntry);
        }
예제 #4
0
        public InventoryEntry CreateInventoryEntry(InventoryEntryDraft inventoryEntryDraft)
        {
            IClient        commerceToolsClient = this.GetService <IClient>();
            InventoryEntry inventoryEntry      = commerceToolsClient
                                                 .ExecuteAsync(new CreateCommand <InventoryEntry>(inventoryEntryDraft)).Result;

            return(inventoryEntry);
        }
예제 #5
0
        public static InventoryEntryDraft DefaultInventoryEntryDraft(InventoryEntryDraft inventoryEntryDraft)
        {
            var randomInt = TestingUtility.RandomInt();

            inventoryEntryDraft.Sku               = $"Sku{randomInt}";
            inventoryEntryDraft.QuantityOnStock   = TestingUtility.RandomInt(100, 1000);
            inventoryEntryDraft.RestockableInDays = TestingUtility.RandomInt(1, 100);
            return(inventoryEntryDraft);
        }
예제 #6
0
        public InventoryEntry CreateInventoryEntryWithCustomFields()
        {
            InventoryEntryDraft draft = this.CreateInventoryEntryDraftWithCustomFields();
            IClient             commerceToolsClient = this.GetService <IClient>();
            InventoryEntry      inventoryEntry      =
                commerceToolsClient.ExecuteAsync(new CreateCommand <InventoryEntry>(draft)).Result;

            return(inventoryEntry);
        }
        public void CreateInventoryEntry()
        {
            IClient             commerceToolsClient = this.inventoryFixture.GetService <IClient>();
            InventoryEntryDraft inventoryEntryDraft = this.inventoryFixture.GetInventoryEntryDraft();
            InventoryEntry      inventoryEntry      = commerceToolsClient
                                                      .ExecuteAsync(new CreateCommand <InventoryEntry>(inventoryEntryDraft)).Result;

            this.inventoryFixture.InventoryEntries.Add(inventoryEntry);
            Assert.Equal(inventoryEntryDraft.Sku, inventoryEntry.Sku);
        }
예제 #8
0
        public InventoryEntryDraft GetInventoryEntryDraft()
        {
            Product product = this.productFixture.CreateProduct(true);

            this.productFixture.ProductsToDelete.Add(product);

            InventoryEntryDraft inventoryEntryDraft = new InventoryEntryDraft();

            inventoryEntryDraft.Sku               = product.MasterData.Current.MasterVariant.Sku;
            inventoryEntryDraft.QuantityOnStock   = this.RandomInt(100, 1000);
            inventoryEntryDraft.RestockableInDays = this.RandomInt(1, 100);
            return(inventoryEntryDraft);
        }
예제 #9
0
        public static InventoryEntryDraft DefaultInventoryEntryDraftWithCustomType(InventoryEntryDraft draft, Type type, Fields fields)
        {
            var customFieldsDraft = new CustomFieldsDraft
            {
                Type   = type.ToKeyResourceIdentifier(),
                Fields = fields
            };

            var inventoryEntryDraft = DefaultInventoryEntryDraft(draft);

            inventoryEntryDraft.Custom = customFieldsDraft;

            return(inventoryEntryDraft);
        }
예제 #10
0
        public InventoryEntryDraft CreateInventoryEntryDraftWithCustomFields()
        {
            InventoryEntryDraft draft             = this.GetInventoryEntryDraft();
            CustomFieldsDraft   customFieldsDraft = new CustomFieldsDraft();
            Type type = this.typeFixture.CreateType();

            this.typeFixture.TypesToDelete.Add(type);
            customFieldsDraft.Type = new ResourceIdentifier <Type> {
                Key = type.Key
            };
            customFieldsDraft.Fields = this.CreateNewFields();
            draft.Custom             = customFieldsDraft;
            return(draft);
        }
예제 #11
0
        /// <summary>
        /// Gets a test inventory draft.
        /// </summary>
        /// <param name="project">Project</param>
        /// <returns>InventoryDraft</returns>
        public static InventoryEntryDraft GetTestInventoryDraft(Project.Project project)
        {
            string   sku               = Helper.GetRandomString(10);
            int      quantityOnStock   = Helper.GetRandomNumber(1, 10);
            int      restockableInDays = Helper.GetRandomNumber(1, 10);
            DateTime expectedDelivery  = DateTime.UtcNow.AddDays(Helper.GetRandomDouble(1, 10));

            InventoryEntryDraft inventoryEntryDraft = new InventoryEntryDraft(sku);

            inventoryEntryDraft.QuantityOnStock   = quantityOnStock;
            inventoryEntryDraft.RestockableInDays = restockableInDays;
            inventoryEntryDraft.ExpectedDelivery  = expectedDelivery;

            return(inventoryEntryDraft);
        }
예제 #12
0
        public async Task ShouldCreateAndDeleteInventoryAsync()
        {
            InventoryEntryDraft       inventoryDraft = Helper.GetTestInventoryDraft(_project);
            Response <InventoryEntry> response       = await _client.Inventories().CreateInventoryEntryAsync(inventoryDraft);

            Assert.IsTrue(response.Success);

            InventoryEntry inventory = response.Result;

            Assert.NotNull(inventory.Id);

            string deletedInventoryId = inventory.Id;

            response = await _client.Inventories().DeleteInventoryEntryAsync(inventory);

            Assert.IsTrue(response.Success);

            response = await _client.Inventories().GetInventoryEntryByIdAsync(deletedInventoryId);

            Assert.IsFalse(response.Success);
        }
예제 #13
0
        private Product CreateCustomizedProduct(string sku = null, string productKey = null,
                                                string productVariantKey = null, TaxCategory taxCategory = null, List <PriceDraft> prices = null,
                                                State state = null, List <Attribute> attributes          = null,
                                                ProductVariantAvailability productVariantAvailability      = null, Channel supplyChannel       = null,
                                                Dictionary <string, List <SearchKeywords> > searchKeywords = null, LocalizedString productName = null)
        {
            var productDraft = this.productFixture.GetProductDraft();

            productDraft.MasterVariant.Sku = sku;
            productDraft.Key = productKey;
            productDraft.MasterVariant.Key        = productVariantKey;
            productDraft.MasterVariant.Prices     = prices;
            productDraft.MasterVariant.Attributes = attributes;
            productDraft.TaxCategory    = taxCategory?.ToReference();
            productDraft.State          = state?.ToReference();
            productDraft.SearchKeywords = searchKeywords;
            productDraft.Name           = productName ?? new LocalizedString()
            {
                { "en", TestingUtility.RandomString(10) }
            };

            var product = this.productFixture.CreateProduct(productDraft);

            if (productVariantAvailability != null)
            {
                // then add inventory it for this product, and get product again
                var inventoryDraft = new InventoryEntryDraft
                {
                    Sku               = product.MasterData.Staged.MasterVariant.Sku,
                    QuantityOnStock   = productVariantAvailability.AvailableQuantity,
                    SupplyChannel     = supplyChannel?.ToReference(),
                    RestockableInDays = productVariantAvailability.RestockableInDays
                };
                this.CreateInventoryEntry(inventoryDraft);
                product = this.productFixture.GetProductById(product.Id);
            }

            this.productFixture.ProductsToDelete.Add(product);
            return(product);
        }
예제 #14
0
        public static InventoryEntry CreateOrRetrieveBySku(
            IClient client,
            string sku,
            InventoryEntryDraft draft,
            Func <InventoryEntryDraft, InventoryEntryDraft> draftAction
            )
        {
            InventoryEntry inventoryEntry = null;
            var            queryCommand   = new QueryCommand <InventoryEntry>();

            queryCommand.Where(ie => ie.Sku == sku.valueOf());
            var returnedSet = client.ExecuteAsync(queryCommand).Result;

            if (returnedSet.Count == 1) //it's exists
            {
                inventoryEntry = returnedSet.Results[0];
            }
            else
            {
                var buildDraft = draftAction.Invoke(draft);
                inventoryEntry = CreateResource(client, buildDraft).Result;
            }
            return(inventoryEntry);
        }
예제 #15
0
        public static InventoryEntryDraft DefaultInventoryEntryDraftWithSpecificQuantity(InventoryEntryDraft draft, long quantity)
        {
            var inventoryEntryDraft = DefaultInventoryEntryDraft(draft);

            inventoryEntryDraft.QuantityOnStock = quantity;
            return(inventoryEntryDraft);
        }