示例#1
0
        void it_can_encodes_to_a_minimum_length()
        {
            var h = new HashIds(salt, 18);

            h.Encode(1).Should().Be("aJEDngB0NV05ev1WwP");

            h.Encode(4140, 21147, 115975, 678570, 4213597, 27644437).
            Should().Be("pLMlCWnJSXr1BSpKgqUwbJ7oimr7l6");
        }
示例#2
0
        void issue_18_it_should_return_empty_string_if_negative_numbers()
        {
            var hashids = new HashIds("this is my salt");

            hashids.Encode(1, 4, 5, -3).Should().Be(string.Empty);
            hashids.EncodeLong(4, 5, 2, -4).Should().Be(string.Empty);
        }
示例#3
0
        void Encode_single()
        {
            var hashids   = new HashIds();
            var stopWatch = Stopwatch.StartNew();

            for (var i = 1; i < 10001; i++)
            {
                hashids.Encode(i);
            }
            stopWatch.Stop();
            Trace.WriteLine($"10 000 encodes: {stopWatch.ElapsedMilliseconds}");
        }
示例#4
0
 void it_encodes_a_single_number()
 {
     _hashIds.Encode(1).Should().Be("NV");
     _hashIds.Encode(22).Should().Be("K4");
     _hashIds.Encode(333).Should().Be("OqM");
     _hashIds.Encode(9999).Should().Be("kQVg");
     _hashIds.Encode(123000).Should().Be("58LzD");
     _hashIds.Encode(456000000).Should().Be("5gn6mQP");
     _hashIds.Encode(987654321).Should().Be("oyjYvry");
 }
示例#5
0
        void it_can_encode_with_a_custom_alphabet()
        {
            var h = new HashIds(salt, 0, "ABCDEFGhijklmn34567890-:");

            h.Encode(1, 2, 3, 4, 5).Should().Be("6nhmFDikA0");
        }