protected static string RemovePrefix(string encoded, SerialNumberConfiguration config)
 {
     if (!string.IsNullOrWhiteSpace(config.Prefix) && encoded.StartsWith(config.Prefix))
     {
         encoded = encoded.Substring(config.Prefix.Length);
     }
     return(encoded);
 }
Example #2
0
 public SmallSerialNumber(string initialValue, SerialNumberConfiguration configuration) : this(Decode(initialValue, configuration), configuration)
 {
     initialValue = RemovePrefix(initialValue, configuration);
     if (!configuration.Encoder.CanDecode(initialValue))
     {
         throw new ArgumentException($"Invalid characters were found in the {nameof(initialValue)} argument that the selected encoder cannot decode.");
     }
 }
        public void ToString_ReturnsUnpaddedString_WhenNoMinimumLengthIsSetInConfiguration()
        {
            var config = new SerialNumberConfiguration();
            var serial = Activator.CreateInstance(typeof(TSerialNumber), 1, config);

            var result = serial.ToString();

            Assert.Equal(1, result.Length);
        }
        public void Constructor_InitializedWithPrefixedString_SetsNumericValue()
        {
            var initialValue = "PRE-N4434";
            var config       = new SerialNumberConfiguration()
            {
                Prefix = "PRE-"
            };
            var expected = config.Encoder.Decode("N4434");
            var sut      = new SerialNumber(initialValue, config);

            Assert.Equal(expected, sut.NumericValue);
        }
        public void ToString_ReturnsProperLength_WhenMinimumLengthIsSetInConfiguration()
        {
            var config = new SerialNumberConfiguration()
            {
                MinimumLength = 10, PadCharacter = '0'
            };
            var serial = Activator.CreateInstance(typeof(TSerialNumber), 1, config);

            var result = serial.ToString();

            Assert.Equal(10, result.Length);
        }
        public void ToString_ReturnsNumberWithPrefix_WhenPrefixIsPassedInConfig()
        {
            var config = new SerialNumberConfiguration()
            {
                Prefix = "PRE-"
            };
            var serial = Activator.CreateInstance(typeof(TSerialNumber), 1, config);

            var result = serial.ToString();

            Assert.Equal("PRE-1", result);
        }
 public SerialNumberTests()
 {
     _encoder = new Base36Encoder();
     _config  = new SerialNumberConfiguration(_encoder);
     _sut     = new SerialNumber("A12345B", _config);
 }
Example #8
0
 private static ulong Decode(string initialValue, SerialNumberConfiguration config)
 {
     initialValue = RemovePrefix(initialValue, config);
     return(config.Encoder.DecodeULong(initialValue));
 }
Example #9
0
 public SmallSerialNumber(int initialValue, SerialNumberConfiguration configuration) : this((ulong)initialValue, configuration)
 {
 }
Example #10
0
 public SmallSerialNumber(ulong initialValue, SerialNumberConfiguration configuration) : base(initialValue, configuration)
 {
 }
Example #11
0
 public SerialNumberBase(T initialValue, SerialNumberConfiguration configuration)
 {
     NumericValue  = initialValue;
     Configuration = configuration;
 }
Example #12
0
 public SerialNumber(int initialValue, SerialNumberConfiguration configuration) : this((BigInteger)initialValue, configuration)
 {
 }
Example #13
0
 public SerialNumber(BigInteger initialValue, SerialNumberConfiguration configuration) : base(initialValue, configuration)
 {
 }