コード例 #1
0
        public async Task UpdateFlatForRentAnnouncementAsync_Should_Return_OkObjectResult_With_FlatForRentAnnouncementResponse()
        {
            var flatForRentAnnouncementId            = Guid.NewGuid();
            var updateFlatForRentAnnouncementRequest = new UpdateFlatForRentAnnouncementRequest
            {
                Id            = flatForRentAnnouncementId,
                Title         = "NewTitle",
                SourceUrl     = "http://sourceUrl",
                CityId        = Guid.NewGuid(),
                Description   = "Description",
                Price         = 100,
                NumberOfRooms = NumberOfRooms.One,
                CityDistricts = new List <Guid> {
                    Guid.NewGuid()
                }
            };
            var updateFlatForRentAnnouncementCommand = new UpdateFlatForRentAnnouncementCommand(
                flatForRentAnnouncementId,
                updateFlatForRentAnnouncementRequest.Title,
                updateFlatForRentAnnouncementRequest.SourceUrl,
                updateFlatForRentAnnouncementRequest.CityId,
                updateFlatForRentAnnouncementRequest.Description,
                updateFlatForRentAnnouncementRequest.Price,
                FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnumeration(updateFlatForRentAnnouncementRequest.NumberOfRooms),
                updateFlatForRentAnnouncementRequest.CityDistricts);
            var flatForRentAnnouncementOutputQuery = new FlatForRentAnnouncementOutputQuery(
                updateFlatForRentAnnouncementCommand.FlatForRentAnnouncementId,
                updateFlatForRentAnnouncementCommand.Title,
                updateFlatForRentAnnouncementCommand.SourceUrl,
                updateFlatForRentAnnouncementCommand.CityId,
                DateTimeOffset.UtcNow,
                updateFlatForRentAnnouncementCommand.Description,
                updateFlatForRentAnnouncementCommand.Price,
                updateFlatForRentAnnouncementCommand.NumberOfRooms,
                updateFlatForRentAnnouncementCommand.CityDistricts);
            var flatForRentAnnouncementResponse = new FlatForRentAnnouncementResponse(
                flatForRentAnnouncementOutputQuery.Id,
                flatForRentAnnouncementOutputQuery.Title,
                flatForRentAnnouncementOutputQuery.SourceUrl,
                flatForRentAnnouncementOutputQuery.CityId,
                flatForRentAnnouncementOutputQuery.Created,
                flatForRentAnnouncementOutputQuery.Description,
                flatForRentAnnouncementOutputQuery.Price,
                FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementOutputQuery.NumberOfRooms),
                flatForRentAnnouncementOutputQuery.CityDistricts);

            _mapperMock
            .Setup(x => x.Map <UpdateFlatForRentAnnouncementRequest, UpdateFlatForRentAnnouncementCommand>(It.IsAny <UpdateFlatForRentAnnouncementRequest>()))
            .Returns(updateFlatForRentAnnouncementCommand);
            _communicationBusMock
            .Setup(x => x.SendCommandAsync(It.IsAny <UpdateFlatForRentAnnouncementCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getFlatForRentAnnouncementQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetFlatForRentAnnouncementInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(flatForRentAnnouncementOutputQuery);
            _mapperMock
            .Setup(x => x.Map <FlatForRentAnnouncementOutputQuery, FlatForRentAnnouncementResponse>(It.IsAny <FlatForRentAnnouncementOutputQuery>()))
            .Returns(flatForRentAnnouncementResponse);

            var result = await _controller.UpdateFlatForRentAnnouncementAsync(flatForRentAnnouncementId, updateFlatForRentAnnouncementRequest);

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

            okObjectResult.Value.Should().BeEquivalentTo(flatForRentAnnouncementResponse);
        }
コード例 #2
0
        public async Task CreateFlatForRentAnnouncementAsync_Should_Return_CreatedAtRouteResult_With_FlatForRentAnnouncementResponse()
        {
            var createFlatForRentAnnouncementRequest = new CreateFlatForRentAnnouncementRequest
            {
                Title         = "Title",
                SourceUrl     = "http://sourceUrl",
                CityId        = Guid.NewGuid(),
                Description   = "Description",
                Price         = 100,
                NumberOfRooms = NumberOfRooms.One,
                CityDistricts = new List <Guid> {
                    Guid.NewGuid()
                }
            };
            var createFlatForRentAnnouncementCommand = new CreateFlatForRentAnnouncementCommand(
                Guid.NewGuid(),
                createFlatForRentAnnouncementRequest.Title,
                createFlatForRentAnnouncementRequest.SourceUrl,
                createFlatForRentAnnouncementRequest.CityId,
                createFlatForRentAnnouncementRequest.Description,
                createFlatForRentAnnouncementRequest.Price,
                FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnumeration(createFlatForRentAnnouncementRequest.NumberOfRooms),
                createFlatForRentAnnouncementRequest.CityDistricts);
            var flatForRentAnnouncementOutputQuery = new FlatForRentAnnouncementOutputQuery(
                createFlatForRentAnnouncementCommand.FlatForRentAnnouncementId,
                createFlatForRentAnnouncementCommand.Title,
                createFlatForRentAnnouncementCommand.SourceUrl,
                createFlatForRentAnnouncementCommand.CityId,
                DateTimeOffset.UtcNow,
                createFlatForRentAnnouncementCommand.Description,
                createFlatForRentAnnouncementCommand.Price,
                createFlatForRentAnnouncementCommand.NumberOfRooms,
                createFlatForRentAnnouncementCommand.CityDistricts);
            var flatForRentAnnouncementResponse = new FlatForRentAnnouncementResponse(
                flatForRentAnnouncementOutputQuery.Id,
                flatForRentAnnouncementOutputQuery.Title,
                flatForRentAnnouncementOutputQuery.SourceUrl,
                flatForRentAnnouncementOutputQuery.CityId,
                flatForRentAnnouncementOutputQuery.Created,
                flatForRentAnnouncementOutputQuery.Description,
                flatForRentAnnouncementOutputQuery.Price,
                FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementOutputQuery.NumberOfRooms),
                flatForRentAnnouncementOutputQuery.CityDistricts);

            _mapperMock
            .Setup(x => x.Map <CreateFlatForRentAnnouncementRequest, CreateFlatForRentAnnouncementCommand>(It.IsAny <CreateFlatForRentAnnouncementRequest>()))
            .Returns(createFlatForRentAnnouncementCommand);
            _communicationBusMock
            .Setup(x => x.SendCommandAsync(It.IsAny <CreateFlatForRentAnnouncementCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getFlatForRentAnnouncementQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetFlatForRentAnnouncementInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(flatForRentAnnouncementOutputQuery);
            _mapperMock
            .Setup(x => x.Map <FlatForRentAnnouncementOutputQuery, FlatForRentAnnouncementResponse>(It.IsAny <FlatForRentAnnouncementOutputQuery>()))
            .Returns(flatForRentAnnouncementResponse);

            var result = await _controller.CreateFlatForRentAnnouncementAsync(createFlatForRentAnnouncementRequest);

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

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