Exemplo n.º 1
0
        public async Task GetFlatForRentAnnouncementAsync_Should_Return_OkObjectResult_With_FlatForRentAnnouncementResponses()
        {
            var flatForRentAnnouncementOutputQuery = new FlatForRentAnnouncementOutputQuery(Guid.NewGuid(), "Title",
                                                                                            "http://sourceUrl", Guid.NewGuid(), DateTimeOffset.UtcNow, "Description", 100,
                                                                                            NumberOfRoomsEnumeration.One, new List <Guid>());
            var flatForRentAnnouncementResponse = new FlatForRentAnnouncementResponse(
                flatForRentAnnouncementOutputQuery.Id,
                flatForRentAnnouncementOutputQuery.Title,
                flatForRentAnnouncementOutputQuery.SourceUrl,
                flatForRentAnnouncementOutputQuery.CityId,
                flatForRentAnnouncementOutputQuery.Created,
                flatForRentAnnouncementOutputQuery.Description,
                flatForRentAnnouncementOutputQuery.Price,
                FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementOutputQuery.NumberOfRooms),
                flatForRentAnnouncementOutputQuery.CityDistricts);

            _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.GetFlatForRentAnnouncementAsync(flatForRentAnnouncementOutputQuery.Id);

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

            okResult.Value.Should().BeEquivalentTo(flatForRentAnnouncementResponse);
        }
Exemplo n.º 2
0
        public async Task HandleAsync_Should_Return_FlatForRentAnnouncementOutputQuery()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            var flatForRentAnnouncementOutputQuery = new FlatForRentAnnouncementOutputQuery(flatForRentAnnouncement.Id,
                                                                                            flatForRentAnnouncement.Title, flatForRentAnnouncement.SourceUrl, flatForRentAnnouncement.CityId,
                                                                                            flatForRentAnnouncement.Created, flatForRentAnnouncement.Description, flatForRentAnnouncement.Price,
                                                                                            flatForRentAnnouncement.NumberOfRooms, flatForRentAnnouncement.CityDistricts);

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);
            _mapperMock
            .Setup(x => x.Map <FlatForRentAnnouncement, FlatForRentAnnouncementOutputQuery>(It.IsAny <FlatForRentAnnouncement>()))
            .Returns(flatForRentAnnouncementOutputQuery);

            var result = await _queryHandler.HandleAsync(new GetFlatForRentAnnouncementInputQuery(flatForRentAnnouncement.Id));

            result.Should().BeEquivalentTo(flatForRentAnnouncementOutputQuery);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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 }));
        }