public IHiLoRepository GetRepository(string entityName, IHiLoConfiguration config)
        {
            IHiLoRepository repository = null;

            repository = _factoryFunction(entityName, config);
            repository.PrepareRepository();
            return(repository);
        }
Example #2
0
        private int _currentLo = int.MaxValue;  // starts with the maximum value to ensure the repository's first call

        /// <summary>
        /// Constructor of the class.
        /// </summary>
        /// <param name="repository">An implementation of the repository used to keep the high values.</param>
        /// <param name="maxLo">The value used as the low part of the key.</param>
        public HiLoGenerator(IHiLoRepository repository, int maxLo)
        {
            if (maxLo <= 0)
            {
                throw new ArgumentException("The value of 'maxLo' must be greater than zero.");
            }
            _repository = repository ?? throw new ArgumentException("An valid instance of IHiLoRepository must be provided.");
            _maxLo      = maxLo;
        }
 public ExceptionWrapperRepository(Func <IHiLoRepository> funcCreateRepository)
 {
     try
     {
         _repository = funcCreateRepository();
     }
     catch (Exception ex)
     {
         throw new NHiLoException(ErrorCodes.ErrorWhileCreatingTheRepository, ex);
     }
 }
Example #4
0
            public void ShouldFailCreatingInstanceWithNullAsRepository()
            {
                // Arrange
                IHiLoRepository repository = null;

                try
                {
                    // Act
                    var generator = new HiLoGenerator(repository, 0);
                    // Assert
                    throw new XunitException();
                }
                catch (ArgumentException)
                {
                }
            }