public ScanResultFingerprintUnitTests() { #if FIND_SPECIAL_VALUES Dictionary <int, string> memory = new Dictionary <int, string>(); while (true) { string value = Guid.NewGuid().ToString(); FingerprintContribution fc = new FingerprintContribution("Name", value); int hash = fc.GetHashCode(); if (memory.TryGetValue(hash, out string oldValue)) { if (oldValue == value) { continue; } _specialNameValue1 = oldValue; _specialNameValue2 = value; memory.Clear(); return; } memory.Add(hash, value); } #else _specialNameValue1 = "96303c8f-5ff4-423b-a74d-bab12f37efb2"; _specialNameValue2 = "f6c89020-5898-460d-974c-6227d48ed5e2"; #endif }
public void GetHashCode_TwoObjectsSameKeySameValue_SameHashReturned() { FingerprintContribution contribution1 = new FingerprintContribution("MyKey", "MyValue"); FingerprintContribution contribution2 = new FingerprintContribution("MyKey", "MyValue"); Assert.AreEqual(contribution1.GetHashCode(), contribution2.GetHashCode()); }
public void GetHashCode_TwoObjectsDifferentKeySameValue_DifferentHashesReturned() { FingerprintContribution contribution1 = new FingerprintContribution("abc", "MyValue"); FingerprintContribution contribution2 = new FingerprintContribution("xyz", "MyValue"); Assert.AreNotEqual(contribution1.GetHashCode(), contribution2.GetHashCode()); }
public void Equals_OtherHasSameContributionCountAndHashButDifferentContent_ReturnsFalse() { using (ShimsContext.Create()) { FingerprintContribution fc1 = new FingerprintContribution("Name", _specialNameValue1); FingerprintContribution fc2 = new FingerprintContribution("Name", _specialNameValue2); Assert.AreEqual(fc1.GetHashCode(), fc2.GetHashCode()); A11yElement element1 = new ShimA11yElement { NameGet = () => _specialNameValue1 }; A11yElement element2 = new ShimA11yElement { NameGet = () => _specialNameValue2 }; IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode()); // Ensure that these differ only in specific content Assert.AreEqual(0, fingerprint1.CompareTo(fingerprint2)); Assert.AreEqual(0, fingerprint2.CompareTo(fingerprint1)); Assert.IsFalse(fingerprint1.Equals(fingerprint2)); Assert.IsFalse(fingerprint2.Equals(fingerprint1)); } }