예제 #1
0
        public async Task GetCityDistrictAsync_Should_Return_OkObjectResult_With_CityDistrictResponse()
        {
            var cityDistrictOutputQuery = new CityDistrictOutputQuery(Guid.NewGuid(), Array.Empty <byte>(), "Name",
                                                                      "PolishName", Guid.NewGuid(), Guid.NewGuid(), new List <string> {
                "NameVariant"
            });
            var cityDistrictResponse = new CityDistrictResponse(cityDistrictOutputQuery.Id,
                                                                cityDistrictOutputQuery.RowVersion,
                                                                cityDistrictOutputQuery.Name,
                                                                cityDistrictOutputQuery.PolishName,
                                                                cityDistrictOutputQuery.CityId,
                                                                cityDistrictOutputQuery.ParentId,
                                                                cityDistrictOutputQuery.NameVariants);

            _getCityDistrictQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetCityDistrictInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cityDistrictOutputQuery);
            _mapperMock.Setup(x => x.Map <CityDistrictOutputQuery, CityDistrictResponse>(It.IsAny <CityDistrictOutputQuery>())).Returns(cityDistrictResponse);

            var result = await _controller.GetCityDistrictAsync(cityDistrictOutputQuery.Id);

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

            okResult.Value.Should().BeEquivalentTo(cityDistrictResponse);
        }
예제 #2
0
        public async Task UpdateCityDistrictAsync_Should_Return_OkObjectResult_With_CityDistrictResponse()
        {
            var rowVersion                = new byte[] { 1, 2, 4, 8, 16, 32, 64 };
            var cityDistrictId            = Guid.NewGuid();
            var updateCityDistrictRequest = new UpdateCityDistrictRequest
            {
                Id           = cityDistrictId,
                Name         = "Name",
                PolishName   = "PolishName",
                CityId       = Guid.NewGuid(),
                ParentId     = Guid.NewGuid(),
                NameVariants = new List <string> {
                    "NameVariant"
                }
            };
            var updateCityDistrictCommand = new UpdateCityDistrictCommand(updateCityDistrictRequest.Id,
                                                                          rowVersion,
                                                                          updateCityDistrictRequest.Name,
                                                                          updateCityDistrictRequest.PolishName,
                                                                          updateCityDistrictRequest.CityId,
                                                                          updateCityDistrictRequest.ParentId,
                                                                          updateCityDistrictRequest.NameVariants);
            var cityDistrictOutputQuery = new CityDistrictOutputQuery(updateCityDistrictCommand.CityDistrictId,
                                                                      new byte[] { 1, 2, 4, 8, 16, 32, 128 },
                                                                      updateCityDistrictCommand.Name,
                                                                      updateCityDistrictCommand.PolishName,
                                                                      updateCityDistrictCommand.CityId,
                                                                      updateCityDistrictCommand.ParentId,
                                                                      updateCityDistrictCommand.NameVariants);
            var cityDistrictResponse = new CityDistrictResponse(cityDistrictOutputQuery.Id,
                                                                cityDistrictOutputQuery.RowVersion,
                                                                cityDistrictOutputQuery.Name,
                                                                cityDistrictOutputQuery.PolishName,
                                                                cityDistrictOutputQuery.CityId,
                                                                cityDistrictOutputQuery.ParentId,
                                                                cityDistrictOutputQuery.NameVariants);

            _mapperMock.Setup(x => x.Map <UpdateCityDistrictRequest, UpdateCityDistrictCommand>(It.IsAny <UpdateCityDistrictRequest>()))
            .Returns(updateCityDistrictCommand);
            _communicationBusMock.Setup(x => x.SendCommandAsync(It.IsAny <UpdateCityDistrictCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getCityDistrictQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetCityDistrictInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cityDistrictOutputQuery);
            _mapperMock.Setup(x => x.Map <CityDistrictOutputQuery, CityDistrictResponse>(It.IsAny <CityDistrictOutputQuery>())).Returns(cityDistrictResponse);

            var result = await _controller.UpdateCityDistrictAsync(cityDistrictId, updateCityDistrictRequest, rowVersion);

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

            okObjectResult.Value.Should().BeEquivalentTo(cityDistrictResponse);
        }
예제 #3
0
        public async Task CreateCityDistrictAsync_Should_Return_CreatedAtRouteResult_With_CityDistrictResponse()
        {
            var createCityDistrictRequest = new CreateCityDistrictRequest
            {
                Name         = "Name",
                PolishName   = "PolishName",
                CityId       = Guid.NewGuid(),
                ParentId     = Guid.NewGuid(),
                NameVariants = new List <string> {
                    "NameVariant"
                }
            };
            var createCityDistrictCommand = new CreateCityDistrictCommand(Guid.NewGuid(),
                                                                          createCityDistrictRequest.Name,
                                                                          createCityDistrictRequest.PolishName,
                                                                          createCityDistrictRequest.CityId,
                                                                          createCityDistrictRequest.ParentId,
                                                                          createCityDistrictRequest.NameVariants);
            var cityDistrictOutputQuery = new CityDistrictOutputQuery(createCityDistrictCommand.CityDistrictId,
                                                                      Array.Empty <byte>(),
                                                                      createCityDistrictCommand.Name,
                                                                      createCityDistrictCommand.PolishName,
                                                                      createCityDistrictCommand.CityId,
                                                                      createCityDistrictCommand.ParentId,
                                                                      createCityDistrictCommand.NameVariants);
            var cityDistrictResponse = new CityDistrictResponse(cityDistrictOutputQuery.Id,
                                                                cityDistrictOutputQuery.RowVersion,
                                                                cityDistrictOutputQuery.Name,
                                                                cityDistrictOutputQuery.PolishName,
                                                                cityDistrictOutputQuery.CityId,
                                                                cityDistrictOutputQuery.ParentId,
                                                                cityDistrictOutputQuery.NameVariants);

            _mapperMock.Setup(x =>
                              x.Map <CreateCityDistrictRequest, CreateCityDistrictCommand>(It.IsAny <CreateCityDistrictRequest>()))
            .Returns(createCityDistrictCommand);
            _communicationBusMock.Setup(x =>
                                        x.SendCommandAsync(It.IsAny <CreateCityDistrictCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getCityDistrictQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetCityDistrictInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cityDistrictOutputQuery);
            _mapperMock.Setup(x => x.Map <CityDistrictOutputQuery, CityDistrictResponse>(It.IsAny <CityDistrictOutputQuery>())).Returns(cityDistrictResponse);

            var result = await _controller.CreateCityDistrictAsync(createCityDistrictRequest);

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

            createdAtRouteResult.Value.Should().BeEquivalentTo(cityDistrictResponse);
            createdAtRouteResult.RouteName.Should().BeEquivalentTo("GetCityDistrict");
            createdAtRouteResult.RouteValues.Should().BeEquivalentTo(new RouteValueDictionary(new { id = cityDistrictResponse.Id }));
        }
예제 #4
0
        private static string PrepareExpectedResponse(CityDistrictEntity cityDistrictEntity)
        {
            var cityDistrictResponse = new CityDistrictResponse(cityDistrictEntity.Id,
                                                                cityDistrictEntity.RowVersion,
                                                                cityDistrictEntity.Name,
                                                                cityDistrictEntity.PolishName,
                                                                cityDistrictEntity.CityId,
                                                                cityDistrictEntity.ParentId,
                                                                cityDistrictEntity.NameVariants.Select(x => x.Value));
            var settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultTestPlatformContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                }
            };

            return(JsonConvert.SerializeObject(cityDistrictResponse, settings));
        }
예제 #5
0
        private static async Task <string> PrepareExpectedResponseAsync(RivaAdministrativeDivisionsDbContext context, string cityDistrictName)
        {
            var cityDistrictEntity = await context.CityDistricts.Include(x => x.NameVariants)
                                     .SingleOrDefaultAsync(x => x.Name.Equals(cityDistrictName));

            var cityDistrictResponse = new CityDistrictResponse(cityDistrictEntity.Id,
                                                                cityDistrictEntity.RowVersion,
                                                                cityDistrictEntity.Name,
                                                                cityDistrictEntity.PolishName,
                                                                cityDistrictEntity.CityId,
                                                                cityDistrictEntity.ParentId,
                                                                cityDistrictEntity.NameVariants.Select(x => x.Value));
            var settings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultTestPlatformContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                }
            };

            return(JsonConvert.SerializeObject(cityDistrictResponse, settings));
        }