Esempio n. 1
0
        // POST api/humans
        public void Post([FromBody] HumanModel humanToSave)
        {
            var human = new Human
            {
                name = humanToSave.Name,
                age  = humanToSave.Age
            };

            while (true)
            {
                try
                {
                    human.id = _stringGeneratorService.GenerateString(10);
                    _apiBackend.CreateHuman(human);
                    break;
                }
                catch (FaultException <DomainFault> exception)
                {
                    if (exception.Detail.Code != DomainError.IdAlreadyExists)
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 2
0
        private IDataGenerator ResolveStringGenerator(IRandomNumberGenerator random, DataGenerationHint[] hints, bool isNullable)
        {
            int minLength;
            int maxLength = this.GetMaxLengthAndCheckLengthRange(hints, out minLength);

            bool ansiString = hints.OfType <AnsiStringHint>().Any();

            IStringGenerator stringGenerator = ansiString ? this.AnsiStringGenerator : this.UnicodeStringGenerator;

            var stringPrefixHint = hints.OfType <StringPrefixHint>().SingleOrDefault();

            if (stringPrefixHint != null)
            {
                string prefix = stringPrefixHint.Value;
                ExceptionUtilities.Assert(prefix.Length < maxLength, "the length of string prefix in data generation exceeds the max length limit");
                return(CreateRandomGenerator <string>(random, (r) => prefix + stringGenerator.GenerateString(r, Math.Max(minLength - prefix.Length, 0), maxLength - prefix.Length), hints));
            }

            return(CreateRandomGenerator <string>(random, (r) => stringGenerator.GenerateString(r, minLength, maxLength), hints));
        }
Esempio n. 3
0
        private KeyObject CreateShortKeyInternal(string fullUri)
        {
            var       user = UserId;
            var       key  = _keyGenerator.GenerateString(_currentKeyLength);
            KeyObject uniqKey;

            do
            {
                uniqKey = _repository.GetOrInsertShortKey(fullUri, user, key);
            } while (!uniqKey.Success);

            return(uniqKey);
        }
Esempio n. 4
0
        public async Task <IEnumerable <string> > GenerateSetOfStrings(string alphabet, int lenght, int count, IStringGenerator stringGenerator)
        {
            if (count <= 0)
            {
                throw new ArgumentException("Count can not be less or equal to 0!");
            }

            var tasks = new List <Task <string> >();

            for (int i = 0; i < count; i++)
            {
                tasks.Add(Task <string> .Run(() => stringGenerator.GenerateString(alphabet, lenght)));
            }

            var setOfStrings = await Task.WhenAll(tasks);

            return(setOfStrings);
        }