public void UpdateInventoryEntryByIdSetAddQuantity() { IClient commerceToolsClient = this.inventoryFixture.GetService <IClient>(); InventoryEntry inventoryEntry = this.inventoryFixture.CreateInventoryEntry(); long newAddedQuantity = TestingUtility.RandomInt(1, 10); List <UpdateAction <InventoryEntry> > updateActions = new List <UpdateAction <InventoryEntry> >(); AddQuantityUpdateAction addQuantityUpdateAction = new AddQuantityUpdateAction() { Quantity = newAddedQuantity }; updateActions.Add(addQuantityUpdateAction); //Increments quantityOnStock and updates availableQuantity according to the new quantity InventoryEntry retrievedInventoryEntry = commerceToolsClient .ExecuteAsync(new UpdateByIdCommand <InventoryEntry>(new Guid(inventoryEntry.Id), inventoryEntry.Version, updateActions)).Result; this.inventoryFixture.InventoryEntries.Add(retrievedInventoryEntry); Assert.Equal(inventoryEntry.Id, retrievedInventoryEntry.Id); Assert.Equal(inventoryEntry.QuantityOnStock + newAddedQuantity, retrievedInventoryEntry.QuantityOnStock); Assert.Equal(inventoryEntry.AvailableQuantity + newAddedQuantity, retrievedInventoryEntry.AvailableQuantity); }
public async void UpdateInventoryEntryAddQuantity() { await WithUpdateableInventoryEntry(client, DefaultInventoryEntryDraft, async inventoryEntry => { var newAddedQuantity = TestingUtility.RandomInt(1, 10); var action = new AddQuantityUpdateAction { Quantity = newAddedQuantity }; var updatedInventoryEntry = await client .ExecuteAsync(inventoryEntry.UpdateById(actions => actions.AddUpdate(action))); Assert.Equal(inventoryEntry.QuantityOnStock + newAddedQuantity, updatedInventoryEntry.QuantityOnStock); Assert.Equal(inventoryEntry.AvailableQuantity + newAddedQuantity, updatedInventoryEntry.AvailableQuantity); return(updatedInventoryEntry); }); }