Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteRoomForRentAnnouncementAsync([FromRoute] Guid id)
        {
            var deleteRoomForRentAnnouncementCommand = new DeleteRoomForRentAnnouncementCommand(id);
            await _communicationBus.SendCommandAsync(deleteRoomForRentAnnouncementCommand);

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task HandleAsync_Should_Delete_RoomForRentAnnouncement()
        {
            var roomForRentAnnouncement = RoomForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .SetRoomTypes(new List <RoomTypeEnumeration> {
                RoomTypeEnumeration.Double
            })
                                          .Build();
            var getRoomForRentAnnouncementResult = GetResult <RoomForRentAnnouncement> .Ok(roomForRentAnnouncement);

            var deleteRoomForRentAnnouncementCommand = new DeleteRoomForRentAnnouncementCommand(roomForRentAnnouncement.Id);

            _roomForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getRoomForRentAnnouncementResult);
            _roomForRentAnnouncementRepositoryMock.Setup(x => x.DeleteAsync(It.IsAny <RoomForRentAnnouncement>()))
            .Returns(Task.CompletedTask);

            Func <Task> result = async() => await _commandHandler.HandleAsync(deleteRoomForRentAnnouncementCommand);

            await result.Should().NotThrowAsync <Exception>();
        }
Ejemplo n.º 3
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_RoomForRentAnnouncement_Is_Not_Found()
        {
            var errors = new Collection <IError>
            {
                new Error(RoomForRentAnnouncementErrorCodeEnumeration.NotFound, RoomForRentAnnouncementErrorMessage.NotFound)
            };
            var getRoomForRentAnnouncementResult = GetResult <RoomForRentAnnouncement> .Fail(errors);

            var deleteRoomForRentAnnouncementCommand = new DeleteRoomForRentAnnouncementCommand(Guid.NewGuid());

            _roomForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getRoomForRentAnnouncementResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(deleteRoomForRentAnnouncementCommand);

            var exceptionResult = await result.Should().ThrowExactlyAsync <ResourceNotFoundException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }