internal bool Match(TokenCacheKey key) { return(key != null && (key.Authority == this.Authority && key.ScopeEquals(this.Scope) && key.Equals(key.ClientId, this.ClientId) && key.UniqueId == this.UniqueId && key.Equals(key.DisplayableId, this.DisplayableId) && (key.HomeObjectId == this.HomeObjectId) && key.Equals(key.Policy, this.Policy))); }
public void TokenCacheKey_Equals_SameInstancesAreEqual() { // Setup var testSubject = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, DisplayableId); // Act var result = testSubject.Equals(testSubject); // Verify Assert.IsTrue(result, "Expected same instance to be considered equal"); }
public void TokenCacheKey_Equals_SameValuesDifferenceInstancesAreEqual() { // Setup var testSubject1 = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, DisplayableId); var testSubject2 = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, DisplayableId); // Act var result1 = testSubject1.Equals(testSubject2); var result2 = testSubject2.Equals(testSubject1); // Verify Assert.IsTrue(result1, "Expected different instance with same values to be considered equal"); Assert.IsTrue(result2, "Expected different instance with same values to be considered equal"); }
public void TokenCacheKey_Equals_DifferentValuesAreNotEqual() { // Setup var referenceSubject = new TokenCacheKey(Authority, Resource, ClientId, SubjectType, UniqueId, DisplayableId); foreach (var other in ChangeEachProperty(referenceSubject, "a different value", TokenSubjectType.Client)) { // Act var result1 = referenceSubject.Equals(other); var result2 = other.Equals(referenceSubject); // Verify Assert.IsFalse(result1, "Expected NOT to be equal." + Environment.NewLine + AsString(referenceSubject) + Environment.NewLine + "should not equal" + Environment.NewLine + AsString(other)); Assert.IsFalse(result2, "Expected NOT to be equal." + Environment.NewLine + AsString(referenceSubject) + Environment.NewLine + "should not equal" + Environment.NewLine + AsString(other)); } }
public void TestEquals() { TokenCacheKey key1 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); TokenCacheKey key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsTrue(key1.Equals(key2)); //scope key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.ScopeForAnotherResource, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //different case scope HashSet <string> uppercaseScope = new HashSet <string>(); foreach (var item in TestConstants.DefaultScope) { uppercaseScope.Add(item.ToUpper(CultureInfo.InvariantCulture)); } key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, uppercaseScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsTrue(key1.Equals(key2)); //authority key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant + "more", TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(null, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //null scope key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, null, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //client id key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, null, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId + "more", TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //unique id key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, null, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId + "more", TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //displayable id key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, null, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId + "more", TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //root id key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, null, TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId + "more", TestConstants.DefaultPolicy); Assert.IsFalse(key1.Equals(key2)); //policy key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, null); Assert.IsFalse(key1.Equals(key2)); key2 = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy + "more"); Assert.IsFalse(key1.Equals(key2)); // mistmatched object Assert.IsFalse(key1.Equals(new object())); }