Пример #1
0
        public void EqualsMethodReturnsTrueOnlyForIdentifiersWhoseValueMatch()
        {
            var identifier1            = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier.ToUpperInvariant());
            var oppositeCaseIdentifier = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier.ToLowerInvariant());
            var nonMatchingIdentifier  = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier.Replace('5', 'F'));

            Assert.True(identifier1.Equals(identifier1));
            Assert.True(identifier1.Equals(oppositeCaseIdentifier));
            Assert.False(identifier1.Equals(nonMatchingIdentifier));
        }
Пример #2
0
        public void ToStringIncludesAlgorithmIdSuffixAndOriginalHash()
        {
            var identifier1 = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier);

            Assert.NotEqual(HashIdentifier, identifier1.ToString());
            Assert.True(identifier1.ValueString.EndsWith("00", StringComparison.CurrentCultureIgnoreCase));
            Assert.True(identifier1.ValueString.StartsWith(HashIdentifier, StringComparison.CurrentCultureIgnoreCase));

            identifier1 = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier, 0x0F);
            Assert.True(identifier1.ValueString.EndsWith("0F", StringComparison.CurrentCultureIgnoreCase));
        }
Пример #3
0
 public void SupportsValidHexadecimalStringValuesWhenProvidedToTheConstructor()
 {
     Parallel.ForEach(
         new[]
     {
         "A1B3F6AA",
         "1234567890ABCDEF",
         "01abcdef"
     },
         hexValue =>
     {
         var identifier = BlobIdentifier.CreateFromAlgorithmResult(hexValue);
         Assert.NotNull(identifier);
     });
 }
Пример #4
0
        public void SerializationFormatIsCorrect_NewtonsoftJson()
        {
            BlobIdentifier original   = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier, 0xF);
            string         serialized = JsonConvert.SerializeObject(original);
            JObject        jObject    = JObject.Parse(serialized);

            Assert.Equal(1, jObject.Count);

            var identifierProperty = jObject["identifierValue"];

            Assert.NotNull(identifierProperty);

            var bytes = identifierProperty.ToObject <byte[]>();

            Assert.Equal(bytes, original.Bytes);
        }
Пример #5
0
 public void ThrowsWhenNonHexadecimalStringValuesAreProvidedToTheConstructor()
 {
     Parallel.ForEach(
         new[]
     {
         "G1HHZ4",
         "G1-HH-Z4",
         "G1--HH---Z4",
         "@$-A1",
         InvalidHashIdentifier
     },
         nonHexValue =>
     {
         try
         {
             var identifier = BlobIdentifier.CreateFromAlgorithmResult(nonHexValue);
             Assert.Null(identifier);
             Assert.False(true, "Expected ArgumentException was not thrown.");
         }
         catch (ArgumentException)
         {
         }
     });
 }
Пример #6
0
        public void InputHashIsPreservedButCaseIsNot()
        {
            var identifier1 = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier.ToLowerInvariant(), 0xF);

            Assert.True(identifier1.ValueString.Equals(HashIdentifier.ToUpperInvariant() + "0F"));
        }
Пример #7
0
        public void AlgorithmIdIsPreservedWhenPassedIn()
        {
            var identifier1 = BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier, 0xF);

            Assert.True(identifier1.AlgorithmId.Equals(0xF));
        }
Пример #8
0
        private BlobIdentifier CreateBlobIdentifier()
        {
            const string HashIdentifier = "54CE418A2A89A74B42CC39630167795DED5F3B16A75FF32A01B2B01C59697784";

            return(BlobIdentifier.CreateFromAlgorithmResult(HashIdentifier.ToUpperInvariant()));
        }