public void Encode_ReturnsProperString_WhenPassedValueBelow36(ulong input, string expected)
        {
            var bigInput = new BigInteger(input);

            var result = _sut.Encode(bigInput);

            Assert.Equal(expected, result);
        }
        public void Base36StringTest(string str)
        {
            var encodedText = Base36Encoder.Encode(str);
            var decodeStr   = Base36Encoder.DecodeString(encodedText);

            Assert.Equal(str, decodeStr, ignoreCase: true);
        }
        public void Base36LongTest(long num)
        {
            var encodedText = Base36Encoder.Encode(num);
            var decodeNum   = Base36Encoder.DecodeLong(encodedText);

            Assert.Equal(num, decodeNum);
        }
 public void Base36EncodeTest()
 {
     Base36Encoder.Encode(Guid.NewGuid());
     Base36Encoder.Encode(DateTime.UtcNow.Ticks);
     Base36Encoder.Encode("xxxxxxxxx");
     //Base36Encoder.Encode("你好", Encoding.UTF8); // not supported
 }
        public Post Save(string slug, Post content)
        {
            var isNew = string.IsNullOrEmpty(slug);

            if (isNew)
            {
                // No slug was specified, so we need to get the next one
                var docs = db.GetCollection("sequences");

                docs.EnsureIndex(IndexKeys.Ascending("Name"), IndexOptions.SetUnique(true));

                var sequence = docs.FindAndModify(Query.EQ("Name", "slug"), null, Update.Inc("Current", 1), true, true)
                               .GetModifiedDocumentAs <Incrementor>();

                slug = Base36Encoder.Encode(sequence.Current);
            }

            content.Slug = slug;

            content.Version = isNew ? 1 : GetLatestVersion(slug) + 1;

            db.GetCollection <Post>("posts").Save(content, WriteConcern.Acknowledged);

            return(content);
        }
        public void Base36GuidTest()
        {
            var guid        = Guid.NewGuid();
            var encodedText = Base36Encoder.Encode(guid);
            var decodeGuid  = Base36Encoder.DecodeGuid(encodedText);

            Assert.Equal(guid, decodeGuid);
        }
Exemple #7
0
        public WebAppLinkResponse GetLink()
        {
            var autoLoginToken = new WebAutoLoginToken {
                Token     = OAuth.Token,
                Key       = (Int64)(new Random().NextDouble() * 10000000000000000000),
                Secret    = Guid.NewGuid(),
                IPAddress = Request.GetClientIpAddress()
            };

            Database.WebAutoLoginTokenStore.Add(autoLoginToken);
            Database.SaveChanges();

            return(new WebAppLinkResponse {
                UriMask = String.Format(
                    Settings.Default.KmsWebAppUriMask,
                    Base36Encoder.Encode(autoLoginToken.Key)
                    ),
                AutoLoginSecret = autoLoginToken.Secret.ToString("N")
            });
        }