Beispiel #1
0
        public void Should_be_able_to_encode_and_decode(int loopCount)
        {
            for (int i = 1; i <= loopCount; i++)
            {
                var rnd   = new Random();
                var value = rnd.Next(0, int.MaxValue);

                var encoded = basex.Encode(value);
                var decoded = basex.Decode(encoded);

                Assert.Equal(value, decoded);
            }
        }
Beispiel #2
0
        private ShortUrlResult CreateWithoutAlias(ShortUrl shortUrl, string ipAddress, User user, bool withApi)
        {
            Alias alias = new Alias {
                IPAddress = ipAddress, CreatedByApi = withApi, ShortUrl = shortUrl, User = user
            };

            // Associate with url
            shortUrl.Aliases.Add(alias);

            if (user != null)
            {
                user.Aliases.Add(alias);
            }

            // We have to commit to generate the alias id
            unitOfWork.Commit();

            long id = alias.Id;

            // We also need to ensure that the generated alias does not exists.
            // it might happen if the same alias is specified previously by another user
            // we also have to ensure that the generated alias does match with the reserved alias
            while (true)
            {
                string aliasName = baseX.Encode(id);

                if ((shortUrlRepository.GetByAliasName(aliasName) == null) && !reservedAliasRepository.IsMatching(aliasName))
                {
                    alias.Name = aliasName;
                    break;
                }

                // Alias exists, So try next free alias
                id += 1;
            }

            OnCreate(alias);

            return(new ShortUrlResult(CreateShortUrlDTO(alias)));
        }