Exemplo n.º 1
0
        private static async Task <string> PrepareExpectedResponseAsync(ICosmosStore <FlatForRentAnnouncementEntity> cosmosStore)
        {
            var flatForRentAnnouncementEntities = await cosmosStore.Query().ToListAsync();

            var getFlatForRentAnnouncementsCollectionItemResponses = flatForRentAnnouncementEntities.Select(
                flatForRentAnnouncementEntity => new FlatForRentAnnouncementResponse(
                    flatForRentAnnouncementEntity.Id,
                    flatForRentAnnouncementEntity.Title,
                    flatForRentAnnouncementEntity.SourceUrl,
                    flatForRentAnnouncementEntity.CityId,
                    flatForRentAnnouncementEntity.Created,
                    flatForRentAnnouncementEntity.Description,
                    flatForRentAnnouncementEntity.Price,
                    FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementEntity
                                                                              .NumberOfRooms.ConvertToEnumeration()),
                    flatForRentAnnouncementEntity.CityDistricts));
            var collectionResponse =
                new CollectionResponse <FlatForRentAnnouncementResponse>(flatForRentAnnouncementEntities.Count, getFlatForRentAnnouncementsCollectionItemResponses);
            var settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultTestPlatformContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                },
                Converters = new List <JsonConverter> {
                    new IsoDateTimeConverter(), new StringEnumConverter()
                }
            };

            return(JsonConvert.SerializeObject(collectionResponse, settings));
        }
Exemplo n.º 2
0
        public async Task Should_Update_FlatForRentAnnouncement_When_Requesting_By_Administrator_Client()
        {
            var flatForRentAnnouncementEntity = await InsertFlatForRentAnnouncementEntityAsync(_fixture.FlatForRentAnnouncementEntityCosmosStore);

            var updateFlatForRentAnnouncementRequest = new UpdateFlatForRentAnnouncementRequest
            {
                Id            = flatForRentAnnouncementEntity.Id,
                Title         = "UpdateFlatForRentAnnouncementNewName",
                SourceUrl     = flatForRentAnnouncementEntity.SourceUrl,
                CityId        = flatForRentAnnouncementEntity.CityId,
                Description   = flatForRentAnnouncementEntity.Description,
                Price         = flatForRentAnnouncementEntity.Price,
                NumberOfRooms = FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(flatForRentAnnouncementEntity.NumberOfRooms.ConvertToEnumeration()),
                CityDistricts = flatForRentAnnouncementEntity.CityDistricts
            };
            var updateFlatForRentAnnouncementRequestString = JsonConvert.SerializeObject(updateFlatForRentAnnouncementRequest);
            var requestContent = new StringContent(updateFlatForRentAnnouncementRequestString, Encoding.UTF8, "application/json");

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

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

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

            var expectedResponse = await PrepareExpectedResponseAsync(flatForRentAnnouncementEntity.Id, _fixture.FlatForRentAnnouncementEntityCosmosStore);

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.OK);
            responseContentString.Should().BeEquivalentTo(expectedResponse);
        }
Exemplo n.º 3
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.º 4
0
        public async Task GetFlatForRentAnnouncementsAsync_Should_Return_OkObjectResult_With_CollectionResponse_With_FlatForRentAnnouncementResponses()
        {
            var flatForRentAnnouncementOutputQueries = new List <FlatForRentAnnouncementOutputQuery>
            {
                new FlatForRentAnnouncementOutputQuery(Guid.NewGuid(), "Title", "http://sourceUrl",
                                                       Guid.NewGuid(), DateTimeOffset.UtcNow, "Description", 100, NumberOfRoomsEnumeration.One,
                                                       new List <Guid>())
            };
            var collectionOutputQuery =
                new CollectionOutputQuery <FlatForRentAnnouncementOutputQuery>(flatForRentAnnouncementOutputQueries.Count, flatForRentAnnouncementOutputQueries);
            var flatForRentAnnouncementResponses = flatForRentAnnouncementOutputQueries.Select(output =>
                                                                                               new FlatForRentAnnouncementResponse(output.Id, output.Title, output.SourceUrl, output.CityId,
                                                                                                                                   output.Created, output.Description, output.Price,
                                                                                                                                   FlatForRentAnnouncementProfile.ConvertToNumberOfRoomsEnum(output.NumberOfRooms),
                                                                                                                                   output.CityDistricts))
                                                   .ToList();
            var collectionResponse = new CollectionResponse <FlatForRentAnnouncementResponse>(flatForRentAnnouncementResponses.Count, flatForRentAnnouncementResponses);

            _getFlatForRentAnnouncementsQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetFlatForRentAnnouncementsInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(collectionOutputQuery);
            _mapperMock
            .Setup(x => x.Map <CollectionOutputQuery <FlatForRentAnnouncementOutputQuery>, CollectionResponse <FlatForRentAnnouncementResponse> >(It.IsAny <CollectionOutputQuery <FlatForRentAnnouncementOutputQuery> >()))
            .Returns(collectionResponse);

            var result = await _controller.GetFlatForRentAnnouncementsAsync(new GetFlatForRentAnnouncementsRequest());

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

            okResult.Value.Should().BeEquivalentTo(collectionResponse);
        }
Exemplo n.º 5
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.º 6
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 }));
        }