Пример #1
0
        public void AddAdvertisement(Advertisement advertisement)
        {
            const string logPrefix = "AdvertisementService: AddAdvertisement() ";

            try
            {
                _logger.Debug(logPrefix + advertisement);

                if (!advertisement.IsValid)
                {
                    var errorMessages = string.Join("\n", advertisement.GetValidationErrors());
                    throw new ValidationException("Validation errors: " + errorMessages);
                }

                var dataAccessFactory       = new DataAccessFactory(_configuration.DataProvider, _logger);
                var advertisementRepository = dataAccessFactory.GetAdvertisementRepository();
                advertisementRepository.Create(advertisement);
            }
            catch (ValidationException ex)
            {
                _logger.Debug(logPrefix + ex);
                // I don't mind returning the StackTrace and errors for a validation error
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(logPrefix + ex);
                throw new Exception("Exception thrown. Check server logs");
            }
        }
Пример #2
0
        public void Repo_Can_Create_Advertisement()
        {
            // ARRANGE
            var repository = _factory.GetAdvertisementRepository();

            var entity = new Business.Entities.Advertisement
            {
                BookingDateTimeUtc = DateTime.UtcNow,
                ClientName         = "Test",
                DurationSeconds    = 60
            };

            // ACT
            repository.Create(entity);

            // ASSERT
        }
Пример #3
0
        public IEnumerable <Advertisement> GetAdvertisements()
        {
            const string logPrefix = "AdvertisementService: GetAdvertisements() ";

            try
            {
                _logger.Debug(logPrefix);
                var dataAccessFactory       = new DataAccessFactory(_configuration.DataProvider, _logger);
                var advertisementRepository = dataAccessFactory.GetAdvertisementRepository();
                return(advertisementRepository.GetAll());
            }
            catch (Exception ex)
            {
                _logger.Error(logPrefix + ex);
                throw new Exception("Exception thrown. Check server logs");
            }
        }