public async Task When_UpdatingBucket_Expect_UpdatedBucked() { // Arrange Bucket bucket = new Bucket { Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Size = new Random().Next(int.MaxValue), }; await this.repository.AddAsync(bucket); UpdateBucket.Command command = new UpdateBucket.Command( id: bucket.Id, name: Guid.NewGuid().ToString(), description: Guid.NewGuid().ToString(), size: new Random().Next(int.MaxValue)); UpdateBucket.Handler handler = new UpdateBucket.Handler(this.repository); // Act UpdateBucket.Response response = await handler.Handle(command, default); // Assert Assert.False(response.Created); Assert.True(response.Updated); Assert.Equal(bucket.Id, response.Bucket.Id); Assert.Equal(bucket.Name, response.Bucket.Name); Assert.Equal(bucket.Description, response.Bucket.Description); Assert.Equal(bucket.Size, response.Bucket.Size); }
public void When_InstantiatingResponseWithCreatedSetToFalse_Expect_CreatedFalse() { // Arrange Bucket bucket = new Bucket(); // Act UpdateBucket.Response response = new UpdateBucket.Response(bucket, false); // Assert Assert.Equal(bucket, response.Bucket); Assert.False(response.Created); Assert.True(response.Updated); }
public async Task <ActionResult <Bucket> > UpdateBucket(int bucketId, [FromBody] Bucket bucket) { UpdateBucket.Command command = new UpdateBucket.Command( id: bucketId, name: bucket.Name, description: bucket.Description, size: bucket.Size); UpdateBucket.Response response = await this.mediator.Send(command); bucket = this.mapper.Map <Bucket>(response.Bucket); if (response.Created) { return(this.CreatedAtRoute("GetBucket", new { bucketId }, bucket)); } return(bucket); }