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

            Channel supplyChannel = this.inventoryFixture.channelFixture.CreateChannel(ChannelRole.InventorySupply);

            this.inventoryFixture.channelFixture.ChannelsToDelete.Add(supplyChannel);

            Reference <Channel> channelReference = new Reference <Channel>()
            {
                Id = supplyChannel.Id
            };

            List <UpdateAction <InventoryEntry> > updateActions = new List <UpdateAction <InventoryEntry> >();

            SetSupplyChannelUpdateAction setSupplyChannelUpdateAction = new SetSupplyChannelUpdateAction()
            {
                SupplyChannel = channelReference
            };

            updateActions.Add(setSupplyChannelUpdateAction);

            InventoryEntry retrievedInventoryEntry = commerceToolsClient
                                                     .ExecuteAsync(new UpdateByIdCommand <InventoryEntry>(new Guid(inventoryEntry.Id), inventoryEntry.Version,
                                                                                                          updateActions)).Result;

            this.inventoryFixture.InventoryEntries.Add(retrievedInventoryEntry);

            Assert.Equal(retrievedInventoryEntry.Id, inventoryEntry.Id);
            Assert.Equal(supplyChannel.Id, retrievedInventoryEntry.SupplyChannel.Id);
        }
Example #2
0
        public async void UpdateInventoryEntrySetSupplyChannel()
        {
            await WithChannel(client, async channel =>
            {
                await WithUpdateableInventoryEntry(client, DefaultInventoryEntryDraft,
                                                   async inventoryEntry =>
                {
                    Assert.Null(inventoryEntry.SupplyChannel);
                    var action = new SetSupplyChannelUpdateAction
                    {
                        SupplyChannel = channel.ToKeyResourceIdentifier()
                    };

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

                    Assert.NotNull(updatedInventoryEntry.SupplyChannel);
                    Assert.Equal(channel.Id, updatedInventoryEntry.SupplyChannel.Id);
                    return(updatedInventoryEntry);
                });
            });
        }