コード例 #1
0
        public async Task Should_Update_RoomForRentAnnouncement_When_Requesting_By_Administrator_Client()
        {
            var roomForRentAnnouncementEntity = await InsertRoomForRentAnnouncementEntityAsync(_fixture.RoomForRentAnnouncementEntityCosmosStore);

            var updateRoomForRentAnnouncementRequest = new UpdateRoomForRentAnnouncementRequest
            {
                Id            = roomForRentAnnouncementEntity.Id,
                Title         = "UpdateRoomForRentAnnouncementNewName",
                SourceUrl     = roomForRentAnnouncementEntity.SourceUrl,
                CityId        = roomForRentAnnouncementEntity.CityId,
                Description   = roomForRentAnnouncementEntity.Description,
                Price         = roomForRentAnnouncementEntity.Price,
                RoomTypes     = roomForRentAnnouncementEntity.RoomTypes.Select(x => RoomForRentAnnouncementProfile.ConvertToRoomTypeEnum(x.ConvertToEnumeration())),
                CityDistricts = roomForRentAnnouncementEntity.CityDistricts
            };
            var updateRoomForRentAnnouncementRequestString = JsonConvert.SerializeObject(updateRoomForRentAnnouncementRequest);
            var requestContent = new StringContent(updateRoomForRentAnnouncementRequestString, Encoding.UTF8, "application/json");

            _fixture.AdministratorHttpClient.DefaultRequestHeaders.Add("api-version", "1");

            var response = await _fixture.AdministratorHttpClient.PutAsync($"api/roomForRentAnnouncements/{roomForRentAnnouncementEntity.Id}", requestContent);

            var responseContentString = await response.Content.ReadAsStringAsync();

            var expectedResponse = await PrepareExpectedResponseAsync(roomForRentAnnouncementEntity.Id,
                                                                      _fixture.RoomForRentAnnouncementEntityCosmosStore);

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.OK);
            responseContentString.Should().BeEquivalentTo(expectedResponse);
        }
コード例 #2
0
        public async Task Should_Return_Unauthorized_Status_Code_When_Requesting_By_Anonymous_Client()
        {
            var updateRoomForRentAnnouncementRequest = new UpdateRoomForRentAnnouncementRequest
            {
                Id          = Guid.NewGuid(),
                Title       = "UpdateRoomForRentAnnouncementNewName",
                SourceUrl   = "http://sourceUrl",
                CityId      = CityOptions.City.Id,
                Description = "Description",
                Price       = 1000,
                RoomTypes   = new List <Models.Enums.RoomType> {
                    Models.Enums.RoomType.Single
                },
                CityDistricts = CityDistrictOptions.CityDistricts.Select(x => x.Id)
            };
            var updateRoomForRentAnnouncementRequestString = JsonConvert.SerializeObject(updateRoomForRentAnnouncementRequest);
            var requestContent = new StringContent(updateRoomForRentAnnouncementRequestString, Encoding.UTF8, "application/json");

            _fixture.AnonymousHttpClient.DefaultRequestHeaders.Add("api-version", "1");

            var response = await _fixture.AnonymousHttpClient.PutAsync($"api/roomForRentAnnouncements/{updateRoomForRentAnnouncementRequest.Id}", requestContent);

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Unauthorized);
        }
コード例 #3
0
        public async Task <IActionResult> UpdateRoomForRentAnnouncementAsync([FromRoute] Guid id, [FromBody] UpdateRoomForRentAnnouncementRequest request)
        {
            ValidatePathIdWithRequestBodyId(id, request.Id);
            var updateRoomForRentAnnouncementCommand = _mapper.Map <UpdateRoomForRentAnnouncementRequest, UpdateRoomForRentAnnouncementCommand>(request);
            await _communicationBus.SendCommandAsync(updateRoomForRentAnnouncementCommand);

            var getRoomForRentAnnouncementOutputQuery = await _getRoomForRentAnnouncementQueryHandler.HandleAsync(
                new GetRoomForRentAnnouncementInputQuery(updateRoomForRentAnnouncementCommand
                                                         .RoomForRentAnnouncementId));

            var getRoomForRentAnnouncementResponse = _mapper.Map <RoomForRentAnnouncementOutputQuery, RoomForRentAnnouncementResponse>(getRoomForRentAnnouncementOutputQuery);

            return(Ok(getRoomForRentAnnouncementResponse));
        }
コード例 #4
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);
        }