示例#1
0
        public async Task AddTariffAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _tariffDbServiceMock.Setup(x => x.AddAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new Exception());
            _tariffDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new Exception());
            var tariff = new VisitTariffDto {
                Id = "1", Name = "test"
            };
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

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

            await result.Should().ThrowExactlyAsync <Exception>();
        }
示例#2
0
        public async Task AddTariffAsync__Already_there_is_the_same_element_in_database__Should_return_400BadRequest_response()
        {
            var tariffDto = CreateSightseeingTariffDto(_tariffs[0]);

            _mapperMock.Setup(x => x.Map <VisitTariff>(tariffDto)).Returns(_tariffs[0]);
            _tariffDbServiceMock.Setup(x => x.AddAsync(It.IsNotNull <VisitTariff>())).ThrowsAsync(new InvalidOperationException());
            _tariffDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsNotNull <VisitTariff>())).ThrowsAsync(new InvalidOperationException());
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.AddTariffAsync(tariffDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
示例#3
0
        public async Task AddTariffAsync__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.AddAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new InternalDbServiceException());
            _tariffDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsAny <VisitTariff>())).ThrowsAsync(new InternalDbServiceException());
            var tariff = new VisitTariffDto {
                Id = "1", Name = "test"
            };
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

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

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
示例#4
0
        public async Task AddTariffAsync__Add_succeeded__Should_return_200OK_response_with_added_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.AddAsync(validTariff)).ReturnsAsync(validTariff);
            _tariffDbServiceMock.Setup(x => x.RestrictedAddAsync(validTariff)).ReturnsAsync(validTariff);
            var controller = new VisitTariffsController(_tariffDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.AddTariffAsync(validTariffDto);

            (result as ObjectResult).StatusCode.Should().Be(201);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull();
        }