Exemplo n.º 1
0
        public async Task UpdateTariffAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _tariffDbServiceMock.Setup(x => x.UpdateAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new Exception());
            _tariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new Exception());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.UpdateTariffAsync(_tariffDtos[0].Id, _tariffDtos[0]);

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Exemplo n.º 2
0
        public async Task UpdateTariffAsync__Argument_id_and_id_property_in_element_to_be_updated_mismatches__Should_return_400BadRequest_response()
        {
            var    controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);
            var    tariffDto  = _tariffDtos[0];
            string id         = tariffDto.Id + "_mismatched_id";

            var result = await controller.UpdateTariffAsync(id, tariffDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Exemplo n.º 3
0
        public async Task UpdateTariffAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);
            var tariffDto  = _tariffDtos[0];

            tariffDto.Id = id;

            var result = await controller.UpdateTariffAsync(id, tariffDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Exemplo n.º 4
0
        public async Task UpdateTariffAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException()
        {
            // Example of these errors: database does not exist, table does not exist etc.

            _tariffDbServiceMock.Setup(x => x.UpdateAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new InternalDbServiceException());
            _tariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.UpdateTariffAsync(_tariffDtos[0].Id, _tariffDtos[0]);

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
Exemplo n.º 5
0
        public async Task UpdateTariffAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            var validTariff = new VisitTariff {
                Id = "12312321321321", Name = "Valid name"
            };
            var validTariffDto = CreateSightseeingTariffDto(validTariff);

            _mapperMock.Setup(x => x.Map <VisitTariff>(It.IsNotNull <VisitTariffDto>())).Returns(validTariff);
            _mapperMock.Setup(x => x.Map <VisitTariffDto>(It.IsNotNull <VisitTariff>())).Returns(validTariffDto);
            _tariffDbServiceMock.Setup(x => x.UpdateAsync(It.IsNotNull <VisitTariff>())).ThrowsAsync(new InvalidOperationException());
            _tariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsNotNull <VisitTariff>())).ThrowsAsync(new InvalidOperationException());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.UpdateTariffAsync(validTariffDto.Id, validTariffDto);

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Exemplo n.º 6
0
        public async Task UpdateTariffAsync__Update_succeeded__Should_return_200OK_response_with_updated_element()
        {
            var validTariff = new VisitTariff {
                Id = "12312321321321", Name = "Valid name"
            };
            var validTariffDto = CreateSightseeingTariffDto(validTariff);

            _mapperMock.Setup(x => x.Map <VisitTariff>(It.IsNotNull <VisitTariffDto>())).Returns(validTariff);
            _mapperMock.Setup(x => x.Map <VisitTariffDto>(It.IsNotNull <VisitTariff>())).Returns(validTariffDto);
            _tariffDbServiceMock.Setup(x => x.UpdateAsync(validTariff)).ReturnsAsync(validTariff);
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            _tariffDbServiceMock.Setup(x => x.RestrictedUpdateAsync(validTariff)).ReturnsAsync(validTariff);

            var result = await controller.UpdateTariffAsync(validTariffDto.Id, validTariffDto);

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().BeEquivalentTo(validTariffDto);
        }