Exemple #1
0
        void it_does_not_decode_with_a_different_salt()
        {
            var peppers = new Hashids("this is my pepper");

            hashids.Decode("NkK9").Should().Equal(new[] { 12345 });
            peppers.Decode("NkK9").Should().Equal(new int[0]);
        }
Exemple #2
0
        void it_can_decode_from_a_hash_with_a_minimum_length()
        {
            var h = new Hashids(salt, 8);

            h.Decode("gB0NV05e").Should().Equal(new[] { 1 });
            h.Decode("mxi8XH87").Should().Equal(new[] { 25, 100, 950 });
            h.Decode("KQcmkIW8hX").Should().Equal(new[] { 5, 200, 195, 1 });
        }
Exemple #3
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");
        }
        void issue_14_it_should_decode_encode_hex_correctly()
        {
            var hashids = new Hashids("this is my salt");
            var encoded = hashids.EncodeHex("DEADBEEF");

            encoded.Should().Be("kRNrpKlJ");

            var decoded = hashids.DecodeHex(encoded);

            decoded.Should().Be("DEADBEEF");

            var encoded2 = hashids.EncodeHex("1234567890ABCDEF");
            var decoded2 = hashids.DecodeHex(encoded2);

            decoded2.Should().Be("1234567890ABCDEF");
        }
        void issue_12_should_not_throw_out_of_range_exception()
        {
            var hash        = new Hashids("zXZVFf2N38uV");
            var longs       = new List <long>();
            var rand        = new Random();
            var valueBuffer = new byte[8];
            var randLong    = 0L;

            for (var i = 0; i < 100000; i++)
            {
                rand.NextBytes(valueBuffer);
                randLong = BitConverter.ToInt64(valueBuffer, 0);
                longs.Add(Math.Abs(randLong));
            }

            var encoded = hash.EncodeLong(longs);
            var decoded = hash.DecodeLong(encoded);

            decoded.Should().Equal(longs.ToArray());
        }
 void issue_8_should_not_throw_out_of_range_exception()
 {
     var hashids = new Hashids("janottaa", 6);
     var numbers = hashids.Decode("NgAzADEANAA=");
 }
Exemple #7
0
 public Hashids_test()
 {
     hashids = new Hashids(salt);
 }
Exemple #8
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");
        }