Example #1
0
        public async Task <IActionResult> DeleteCityAsync([FromRoute] Guid id, [FromHeader(Name = "If-Match")] byte[] rowVersion)
        {
            var deleteCityCommand = new DeleteCityCommand(id, rowVersion);
            await _communicationBus.SendCommandAsync(deleteCityCommand);

            return(NoContent());
        }
Example #2
0
        public void ShouldRequireValidCityId()
        {
            var command = new DeleteCityCommand {
                Id = 99
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
Example #3
0
        public async Task <IActionResult> DELETE_CITY([FromBody] DeleteCityCommand command)
        {
            var res = await _mediator.Send(command);

            if (!res.Status.IsSuccessful)
            {
                return(BadRequest(res));
            }
            return(Ok(res));
        }
        public async Task ShouldRequireValidCityId()
        {
            var command = new DeleteCityCommand {
                Id = 99
            };

            var result = await SendAsync(command);

            result.Should().NotBeNull();
            result.Succeeded.Should().BeFalse();
            result.Error.Should().Be(ServiceError.NotFount);
        }
Example #5
0
        public async Task HandleAsync_Should_Throw_ResourceNotFoundException_When_City_Is_Not_Found()
        {
            var command = new DeleteCityCommand(Guid.NewGuid(), Array.Empty <byte>());
            var errors  = new Collection <IError>
            {
                new Error(CityErrorCodeEnumeration.NotFound, CityErrorMessage.NotFound)
            };
            var getCityResult = GetResult <City> .Fail(errors);

            _cityGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getCityResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

            var exceptionResult = await result.Should().ThrowAsync <ResourceNotFoundException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Example #6
0
        public async Task HandleAsync_Should_Throw_PreconditionFailedException_When_RowVersion_Does_Not_Match()
        {
            var command = new DeleteCityCommand(Guid.NewGuid(), new byte[] { 1, 2, 4, 8, 16, 32, 64 });
            var city    = City.Builder()
                          .SetId(command.CityId)
                          .SetRowVersion(new byte[] { 1, 2, 4, 8, 16, 32, 128 })
                          .SetName("Name")
                          .SetPolishName("PolishName")
                          .SetStateId(Guid.NewGuid())
                          .Build();
            var getCityResult = GetResult <City> .Ok(city);

            _cityGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getCityResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

            await result.Should().ThrowAsync <PreconditionFailedException>();
        }
Example #7
0
        public async Task HandleAsync_Should_Delete_City()
        {
            var command = new DeleteCityCommand(Guid.NewGuid(), Array.Empty <byte>());
            var city    = City.Builder()
                          .SetId(command.CityId)
                          .SetRowVersion(Array.Empty <byte>())
                          .SetName("Name")
                          .SetPolishName("PolishName")
                          .SetStateId(Guid.NewGuid())
                          .Build();
            var getCityResult = GetResult <City> .Ok(city);

            _cityGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getCityResult);
            _cityRepositoryMock.Setup(x => x.DeleteAsync(It.IsAny <City>())).Returns(Task.CompletedTask);

            Func <Task> result = async() => await _commandHandler.HandleAsync(command);

            await result.Should().NotThrowAsync <Exception>();
        }
Example #8
0
        public async Task <IActionResult> DeleteCity([FromQuery] DeleteCityCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(new { result }));
        }