示例#1
0
        public async Task GetCurrentTariffAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _tariffDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetCurrentTariffAsync();

            await result.Should().ThrowExactlyAsync <Exception>();
        }
示例#2
0
        public async Task GetCurrentTariffAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            _tariffDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new InvalidOperationException()).Verifiable();
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCurrentTariffAsync();

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
示例#3
0
        public async Task GetCurrentTariffAsync__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.GetAllAsync()).ThrowsAsync(new InternalDbServiceException());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetCurrentTariffAsync();

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
示例#4
0
        public async Task GetCurrentTariffAsync__Data_retrieve_succeeded__Should_return_200Ok_response_with_data()
        {
            _tariffDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(_tariffs.AsEnumerable()).Verifiable();
            _mapperMock.Setup(x => x.Map <VisitTariffDto>(It.IsNotNull <VisitTariff>())).Returns(new VisitTariffDto {
                Id = "1", Name = "mapped from tariff to DTO"
            });
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCurrentTariffAsync();

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull();
        }
示例#5
0
        public async Task GetCurrentTariffAsync__Some_tariffs_have_been_edited_since_the_creation_and_are_the_most_current__Should_return_200Ok_response_with_the_most_current_tariff()
        {
            // NOTE: Some tariffs may have been edited after creation, but there are other newer, unedited tariffs.
            // Regardless of that the latest updated tariff is the most current even if there are other, newer creted, but not updated (or updated latter) tariffs.
            // Example :
            //          tariff 1: created at: 12.12.2018, updated at: 12.6.2019  --> THIS IS THE MOST CURRENT TARIFF
            //          tariff 2: created at: 23.3.2019,  updated at: null       --> THIRD
            //          tariff 3: created at: 23.12.2015, updated at 11.6.2019   --> SECOND

            // _tariffs[1] is the most current in this test case.
            var currentTariffDto = CreateSightseeingTariffDto(_tariffs[1]);

            _tariffDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(_tariffs.AsEnumerable()).Verifiable();
            _mapperMock.Setup(x => x.Map <VisitTariffDto>(It.IsNotNull <VisitTariff>())).Returns(currentTariffDto);
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetCurrentTariffAsync();

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