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 void When_InstantiatingResponseWithCreatedSetToFalse_Expect_CreatedFalse() { // Arrange Item item = new Item(); // Act UpdateItem.Response response = new UpdateItem.Response(item, false); // Assert Assert.Equal(item, response.Item); Assert.False(response.Created); Assert.True(response.Updated); }
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); }