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); } }
public static InventoryEntryDraft DefaultInventoryEntryDraftWithSku(InventoryEntryDraft draft, string sku) { var inventoryEntryDraft = DefaultInventoryEntryDraft(draft); inventoryEntryDraft.Sku = sku; return(inventoryEntryDraft); }
public InventoryEntry CreateInventoryEntry(InventoryEntryDraft draft) { var inventoryEntry = this.inventoryFixture.CreateInventoryEntry(draft); this.inventoryFixture.InventoryEntries.Add(inventoryEntry); return(inventoryEntry); }
public InventoryEntry CreateInventoryEntry(InventoryEntryDraft inventoryEntryDraft) { IClient commerceToolsClient = this.GetService <IClient>(); InventoryEntry inventoryEntry = commerceToolsClient .ExecuteAsync(new CreateCommand <InventoryEntry>(inventoryEntryDraft)).Result; return(inventoryEntry); }
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); }
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); }
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); }
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); }
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); }
/// <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); }
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); }
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); }
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); }
public static InventoryEntryDraft DefaultInventoryEntryDraftWithSpecificQuantity(InventoryEntryDraft draft, long quantity) { var inventoryEntryDraft = DefaultInventoryEntryDraft(draft); inventoryEntryDraft.QuantityOnStock = quantity; return(inventoryEntryDraft); }