示例#1
0
        private static async Task <string> PrepareExpectedResponseAsync(Guid flatForRentAnnouncementId, ICosmosStore <FlatForRentAnnouncementEntity> cosmosStore)
        {
            var flatForRentAnnouncementEntity = await cosmosStore.FindAsync(flatForRentAnnouncementId.ToString());

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

            return(JsonConvert.SerializeObject(flatForRentAnnouncementResponse, settings));
        }
示例#2
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);
        }
示例#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);
        }
示例#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 }));
        }