public async Task When_UpdatingItemFromBucket_Expect_ItemUpdated()
            {
                // Arrange
                Bucket bucket = new Bucket();
                Item   item   = new Item {
                    Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString()
                };

                bucket.AddItem(item);

                await this.repository.AddAsync(bucket);

                UpdateItem.Command command = new UpdateItem.Command(
                    bucketId: bucket.Id,
                    itemId: item.Id,
                    name: Guid.NewGuid().ToString(),
                    description: Guid.NewGuid().ToString());

                UpdateItem.Handler handler = new UpdateItem.Handler(this.repository);

                // Act
                UpdateItem.Response response = await handler.Handle(command, default);

                // Assert
                Assert.False(response.Created);
                Assert.True(response.Updated);
                Assert.Equal(item.Id, response.Item.Id);
                Assert.Equal(command.Name, response.Item.Name);
                Assert.Equal(command.Description, response.Item.Description);
            }
            public async Task When_UpdatingNonExistingItemFromBucket_Expect_NewItem()
            {
                // Arrange
                Bucket bucket = new Bucket();

                await this.repository.AddAsync(bucket);

                UpdateItem.Command command = new UpdateItem.Command(
                    bucketId: bucket.Id,
                    itemId: new Random().Next(int.MaxValue),
                    name: Guid.NewGuid().ToString(),
                    description: Guid.NewGuid().ToString());

                UpdateItem.Handler handler = new UpdateItem.Handler(this.repository);

                // Act
                UpdateItem.Response response = await handler.Handle(command, default);

                // Assert
                Assert.True(response.Created);
                Assert.False(response.Updated);
                Assert.Equal(command.ItemId, response.Item.Id);
                Assert.Equal(command.Name, response.Item.Name);
                Assert.Equal(command.Description, response.Item.Description);
            }
            public async Task When_UpdatingItemFromNonExistingBucket_Expect_BucketNotFoundException()
            {
                // Arrange
                UpdateItem.Command command = new UpdateItem.Command(
                    bucketId: new Random().Next(int.MaxValue),
                    itemId: new Random().Next(int.MaxValue),
                    name: Guid.NewGuid().ToString(),
                    description: null);

                UpdateItem.Handler handler = new UpdateItem.Handler(this.repository);

                // Act
                Exception exception = await Record.ExceptionAsync(() =>
                                                                  handler.Handle(command, default));

                // Assert
                Assert.IsType <BucketNotFoundException>(exception);
            }
        public async Task <ActionResult <Item> > UpdateItem(int bucketId, int itemId, [FromBody] Item item)
        {
            UpdateItem.Command command = new UpdateItem.Command(
                bucketId: bucketId,
                itemId: itemId,
                name: item.Name,
                description: item.Description);

            UpdateItem.Response response = await this.mediator.Send(command);

            item = this.mapper.Map <Item>(response.Item);

            if (response.Created)
            {
                return(this.CreatedAtRoute("GetItem", new { bucketId, itemId }, item));
            }

            return(item);
        }