Example #1
0
        public async Task HandleAsync_Should_Return_RoomForRentAnnouncementOutputQuery()
        {
            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 roomForRentAnnouncementOutputQuery = new RoomForRentAnnouncementOutputQuery(roomForRentAnnouncement.Id,
                                                                                            roomForRentAnnouncement.Title, roomForRentAnnouncement.SourceUrl, roomForRentAnnouncement.CityId,
                                                                                            roomForRentAnnouncement.Created, roomForRentAnnouncement.Description, roomForRentAnnouncement.Price,
                                                                                            roomForRentAnnouncement.RoomTypes, roomForRentAnnouncement.CityDistricts);

            _roomForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getRoomForRentAnnouncementResult);
            _mapperMock
            .Setup(x => x.Map <RoomForRentAnnouncement, RoomForRentAnnouncementOutputQuery>(It.IsAny <RoomForRentAnnouncement>()))
            .Returns(roomForRentAnnouncementOutputQuery);

            var result = await _queryHandler.HandleAsync(new GetRoomForRentAnnouncementInputQuery(roomForRentAnnouncement.Id));

            result.Should().BeEquivalentTo(roomForRentAnnouncementOutputQuery);
        }
Example #2
0
        public async Task GetRoomForRentAnnouncementAsync_Should_Return_OkObjectResult_With_RoomForRentAnnouncementResponses()
        {
            var roomForRentAnnouncementOutputQuery = new RoomForRentAnnouncementOutputQuery(Guid.NewGuid(), "Title",
                                                                                            "http://sourceUrl", Guid.NewGuid(), DateTimeOffset.UtcNow, "Description", 100,
                                                                                            new List <RoomTypeEnumeration>(), new List <Guid>());
            var roomForRentAnnouncementResponse = new RoomForRentAnnouncementResponse(
                roomForRentAnnouncementOutputQuery.Id,
                roomForRentAnnouncementOutputQuery.Title,
                roomForRentAnnouncementOutputQuery.SourceUrl,
                roomForRentAnnouncementOutputQuery.CityId,
                roomForRentAnnouncementOutputQuery.Created,
                roomForRentAnnouncementOutputQuery.Description,
                roomForRentAnnouncementOutputQuery.Price,
                roomForRentAnnouncementOutputQuery.RoomTypes.Select(RoomForRentAnnouncementProfile.ConvertToRoomTypeEnum),
                roomForRentAnnouncementOutputQuery.CityDistricts);

            _getRoomForRentAnnouncementQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoomForRentAnnouncementInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roomForRentAnnouncementOutputQuery);
            _mapperMock
            .Setup(x => x.Map <RoomForRentAnnouncementOutputQuery, RoomForRentAnnouncementResponse>(It.IsAny <RoomForRentAnnouncementOutputQuery>()))
            .Returns(roomForRentAnnouncementResponse);

            var result = await _controller.GetRoomForRentAnnouncementAsync(roomForRentAnnouncementOutputQuery.Id);

            var okResult = result.As <OkObjectResult>();

            okResult.Value.Should().BeEquivalentTo(roomForRentAnnouncementResponse);
        }
Example #3
0
        public async Task UpdateRoomForRentAnnouncementAsync_Should_Return_OkObjectResult_With_RoomForRentAnnouncementResponse()
        {
            var roomForRentAnnouncementId            = Guid.NewGuid();
            var updateRoomForRentAnnouncementRequest = new UpdateRoomForRentAnnouncementRequest
            {
                Id          = roomForRentAnnouncementId,
                Title       = "NewTitle",
                SourceUrl   = "http://sourceUrl",
                CityId      = Guid.NewGuid(),
                Description = "Description",
                Price       = 100,
                RoomTypes   = new List <RoomType> {
                    RoomType.Single
                },
                CityDistricts = new List <Guid> {
                    Guid.NewGuid()
                }
            };
            var updateRoomForRentAnnouncementCommand = new UpdateRoomForRentAnnouncementCommand(
                roomForRentAnnouncementId,
                updateRoomForRentAnnouncementRequest.Title,
                updateRoomForRentAnnouncementRequest.SourceUrl,
                updateRoomForRentAnnouncementRequest.CityId,
                updateRoomForRentAnnouncementRequest.Description,
                updateRoomForRentAnnouncementRequest.Price,
                updateRoomForRentAnnouncementRequest.RoomTypes.Select(RoomForRentAnnouncementProfile.ConvertToRoomTypeEnumeration),
                updateRoomForRentAnnouncementRequest.CityDistricts);
            var roomForRentAnnouncementOutputQuery = new RoomForRentAnnouncementOutputQuery(
                updateRoomForRentAnnouncementCommand.RoomForRentAnnouncementId,
                updateRoomForRentAnnouncementCommand.Title,
                updateRoomForRentAnnouncementCommand.SourceUrl,
                updateRoomForRentAnnouncementCommand.CityId,
                DateTimeOffset.UtcNow,
                updateRoomForRentAnnouncementCommand.Description,
                updateRoomForRentAnnouncementCommand.Price,
                updateRoomForRentAnnouncementCommand.RoomTypes,
                updateRoomForRentAnnouncementCommand.CityDistricts);
            var roomForRentAnnouncementResponse = new RoomForRentAnnouncementResponse(
                roomForRentAnnouncementOutputQuery.Id,
                roomForRentAnnouncementOutputQuery.Title,
                roomForRentAnnouncementOutputQuery.SourceUrl,
                roomForRentAnnouncementOutputQuery.CityId,
                roomForRentAnnouncementOutputQuery.Created,
                roomForRentAnnouncementOutputQuery.Description,
                roomForRentAnnouncementOutputQuery.Price,
                roomForRentAnnouncementOutputQuery.RoomTypes.Select(RoomForRentAnnouncementProfile.ConvertToRoomTypeEnum),
                roomForRentAnnouncementOutputQuery.CityDistricts);

            _mapperMock
            .Setup(x => x.Map <UpdateRoomForRentAnnouncementRequest, UpdateRoomForRentAnnouncementCommand>(It.IsAny <UpdateRoomForRentAnnouncementRequest>()))
            .Returns(updateRoomForRentAnnouncementCommand);
            _communicationBusMock
            .Setup(x => x.SendCommandAsync(It.IsAny <UpdateRoomForRentAnnouncementCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getRoomForRentAnnouncementQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoomForRentAnnouncementInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roomForRentAnnouncementOutputQuery);
            _mapperMock
            .Setup(x => x.Map <RoomForRentAnnouncementOutputQuery, RoomForRentAnnouncementResponse>(It.IsAny <RoomForRentAnnouncementOutputQuery>()))
            .Returns(roomForRentAnnouncementResponse);

            var result = await _controller.UpdateRoomForRentAnnouncementAsync(roomForRentAnnouncementId, updateRoomForRentAnnouncementRequest);

            var okObjectResult = result.As <OkObjectResult>();

            okObjectResult.Value.Should().BeEquivalentTo(roomForRentAnnouncementResponse);
        }
Example #4
0
        public async Task CreateRoomForRentAnnouncementAsync_Should_Return_CreatedAtRouteResult_With_RoomForRentAnnouncementResponse()
        {
            var createRoomForRentAnnouncementRequest = new CreateRoomForRentAnnouncementRequest
            {
                Title       = "Title",
                SourceUrl   = "http://sourceUrl",
                CityId      = Guid.NewGuid(),
                Description = "Description",
                Price       = 100,
                RoomTypes   = new List <RoomType> {
                    RoomType.Double
                },
                CityDistricts = new List <Guid> {
                    Guid.NewGuid()
                }
            };
            var createRoomForRentAnnouncementCommand = new CreateRoomForRentAnnouncementCommand(
                Guid.NewGuid(),
                createRoomForRentAnnouncementRequest.Title,
                createRoomForRentAnnouncementRequest.SourceUrl,
                createRoomForRentAnnouncementRequest.CityId,
                createRoomForRentAnnouncementRequest.Description,
                createRoomForRentAnnouncementRequest.Price,
                createRoomForRentAnnouncementRequest.RoomTypes.Select(RoomForRentAnnouncementProfile.ConvertToRoomTypeEnumeration),
                createRoomForRentAnnouncementRequest.CityDistricts);
            var roomForRentAnnouncementOutputQuery = new RoomForRentAnnouncementOutputQuery(
                createRoomForRentAnnouncementCommand.RoomForRentAnnouncementId,
                createRoomForRentAnnouncementCommand.Title,
                createRoomForRentAnnouncementCommand.SourceUrl,
                createRoomForRentAnnouncementCommand.CityId,
                DateTimeOffset.UtcNow,
                createRoomForRentAnnouncementCommand.Description,
                createRoomForRentAnnouncementCommand.Price,
                createRoomForRentAnnouncementCommand.RoomTypes,
                createRoomForRentAnnouncementCommand.CityDistricts);
            var roomForRentAnnouncementResponse = new RoomForRentAnnouncementResponse(
                roomForRentAnnouncementOutputQuery.Id,
                roomForRentAnnouncementOutputQuery.Title,
                roomForRentAnnouncementOutputQuery.SourceUrl,
                roomForRentAnnouncementOutputQuery.CityId,
                roomForRentAnnouncementOutputQuery.Created,
                roomForRentAnnouncementOutputQuery.Description,
                roomForRentAnnouncementOutputQuery.Price,
                roomForRentAnnouncementOutputQuery.RoomTypes.Select(RoomForRentAnnouncementProfile.ConvertToRoomTypeEnum),
                roomForRentAnnouncementOutputQuery.CityDistricts);

            _mapperMock
            .Setup(x => x.Map <CreateRoomForRentAnnouncementRequest, CreateRoomForRentAnnouncementCommand>(It.IsAny <CreateRoomForRentAnnouncementRequest>()))
            .Returns(createRoomForRentAnnouncementCommand);
            _communicationBusMock
            .Setup(x => x.SendCommandAsync(It.IsAny <CreateRoomForRentAnnouncementCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getRoomForRentAnnouncementQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoomForRentAnnouncementInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roomForRentAnnouncementOutputQuery);
            _mapperMock
            .Setup(x => x.Map <RoomForRentAnnouncementOutputQuery, RoomForRentAnnouncementResponse>(It.IsAny <RoomForRentAnnouncementOutputQuery>()))
            .Returns(roomForRentAnnouncementResponse);

            var result = await _controller.CreateRoomForRentAnnouncementAsync(createRoomForRentAnnouncementRequest);

            var createdAtRouteResult = result.As <CreatedAtRouteResult>();

            createdAtRouteResult.Value.Should().BeEquivalentTo(roomForRentAnnouncementResponse);
            createdAtRouteResult.RouteName.Should().BeEquivalentTo("GetRoomForRentAnnouncement");
            createdAtRouteResult.RouteValues.Should()
            .BeEquivalentTo(new Microsoft.AspNetCore.Routing.RouteValueDictionary(new { id = roomForRentAnnouncementResponse.Id }));
        }