Пример #1
0
        public void And_Encoded_Value_Is_Empty_String_Then_Throws_Exception(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);

            //Act
            var encodingService = new EncodingService(config);

            //Assert
            Assert.Throws <ArgumentException>(() => encodingService.Decode("", encodingType));
        }
Пример #2
0
        public void Then_Decodes_Based_On_EncodingType(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = hashids.EncodeLong(expectedResult);

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.Decode(valueToDecode, encodingType);

            //Assert
            Assert.AreEqual(expectedResult, result);
        }
Пример #3
0
        public void And_Encoded_Value_Is_Invalid_Then_Sets_Result_To_Zero_And_Returns_False(EncodingType encodingType)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = "THIS_IS_NOT_A_VALID_ENCODED_VALUE";

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.TryDecode(valueToDecode, encodingType, out var decodedValue);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(0, decodedValue);
        }
Пример #4
0
        public void And_Encoded_Value_Is_Valid_Then_Sets_Result_To_Decoded_Value_And_Returns_True(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = hashids.EncodeLong(expectedResult);

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.TryDecode(valueToDecode, encodingType, out var decodedValue);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(expectedResult, decodedValue);
        }