public void UpdateInventoryEntryByIdSetRemoveQuantity()
        {
            IClient        commerceToolsClient = this.inventoryFixture.GetService <IClient>();
            InventoryEntry inventoryEntry      = this.inventoryFixture.CreateInventoryEntry();

            long newRemovedQuantity = TestingUtility.RandomInt(1, 10);
            List <UpdateAction <InventoryEntry> > updateActions = new List <UpdateAction <InventoryEntry> >();

            RemoveQuantityUpdateAction removeQuantityUpdateAction = new RemoveQuantityUpdateAction()
            {
                Quantity = newRemovedQuantity
            };

            updateActions.Add(removeQuantityUpdateAction);

            //Decrements 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 - newRemovedQuantity, retrievedInventoryEntry.QuantityOnStock);
            Assert.Equal(inventoryEntry.AvailableQuantity - newRemovedQuantity,
                         retrievedInventoryEntry.AvailableQuantity);
        }
예제 #2
0
        public async void UpdateInventoryEntryRemoveQuantity()
        {
            await WithUpdateableInventoryEntry(client, DefaultInventoryEntryDraft,
                                               async inventoryEntry =>
            {
                long newRemovedQuantity = TestingUtility.RandomInt(1, 10);
                var action = new RemoveQuantityUpdateAction
                {
                    Quantity = newRemovedQuantity
                };

                var updatedInventoryEntry = await client
                                            .ExecuteAsync(inventoryEntry.UpdateById(actions => actions.AddUpdate(action)));


                Assert.Equal(inventoryEntry.QuantityOnStock - newRemovedQuantity,
                             updatedInventoryEntry.QuantityOnStock);
                Assert.Equal(inventoryEntry.AvailableQuantity - newRemovedQuantity,
                             updatedInventoryEntry.AvailableQuantity);
                return(updatedInventoryEntry);
            });
        }