public void TokenCacheKey_GetHashCode_IsNotCurrentCultureDependent() { var initialCulture = Thread.CurrentThread.CurrentCulture; try { // Setup var testSubject = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, "a displayable ID with four types of letter iIİı"); // Act: en-US as current culture Thread.CurrentThread.CurrentCulture = GetEnglishUsCulture(); var enUsHashCode = testSubject.GetHashCode(); // Act: tr-TK as current culture Thread.CurrentThread.CurrentCulture = GetTurkishCulture(); var trTkHashCode = testSubject.GetHashCode(); // Verify Assert.AreEqual(enUsHashCode, trTkHashCode, "Expected hash codes to be the same regardless of current thread culture"); } catch (CultureNotFoundException ex) { Assert.Inconclusive($"The culture {ex.InvalidCultureId} is not available."); } finally { // To ensure isolation with other test cases in this assembly, // ensure the test exits with the same culture it started with. Thread.CurrentThread.CurrentCulture = initialCulture; } }
public void TokenCacheKey_GetHashCode_DifferentValuesAreNotEqual() { // Setup var referenceSubject = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, DisplayableId); var baseCode = referenceSubject.GetHashCode(); foreach (var other in ChangeEachProperty(referenceSubject, "a different value", TokenSubjectType.Client)) { // Act var otherCode = other.GetHashCode(); // Verify Assert.AreNotEqual(baseCode, other, "Expected hash codes NOT to be equal."); } }