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); }