Пример #1
0
            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);
            }
Пример #2
0
            public async Task When_UpdatingNonExistingBucketResultingInDomainConflict_Expect_DomainException()
            {
                // Arrange
                UpdateBucket.Command command = new UpdateBucket.Command(
                    id: new Random().Next(int.MaxValue),
                    name: Guid.NewGuid().ToString(),
                    description: null,
                    size: -1);

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

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

                // Assert
                Assert.IsAssignableFrom <DomainException>(exception);
            }
Пример #3
0
        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);
        }
Пример #4
0
            public async Task When_UpdatingBucketResultingInDomainConflict_Expect_DomainException()
            {
                // Arrange
                Bucket bucket = new Bucket();

                bucket.AddItem(new Item());
                await this.repository.AddAsync(bucket);

                UpdateBucket.Command command = new UpdateBucket.Command(
                    id: bucket.Id,
                    name: Guid.NewGuid().ToString(),
                    description: null,
                    size: 0);

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

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

                // Assert
                Assert.IsAssignableFrom <DomainException>(exception);
            }