private int GenerateHashCode() { unchecked { int hashCode = 17; if (CacheKeyTokens != null) { hashCode = hashCode * 92821 + CacheKeyTokens.GetHashCode( ); } if (UserRuleSet != null) { hashCode = hashCode * 92821 + UserRuleSet.GetHashCode( ); } hashCode = hashCode * 92821 + Bools.GetHashCode( ); if (TimeZoneName != null) { hashCode = hashCode * 92821 + TimeZoneName.GetHashCode( ); } return(hashCode); } }
public void Test_Empty( ) { var set1 = new UserRuleSet(new List <long>( )); var set2 = new UserRuleSet(new List <long>( )); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set1.GetHashCode(), Is.EqualTo(set2.GetHashCode())); }
public void Test_OutOfOrder( ) { var set1 = new UserRuleSet(new List <long>( ) { 3, 2, 1 }); var set2 = new UserRuleSet(new List <long>( ) { 2, 3, 1 }); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set1.GetHashCode( ), Is.EqualTo(set2.GetHashCode( ))); }
public void Test_TwoUsersSameTwoRoles( ) { long user1 = 1; long user2 = 2; long role1 = 3; long role2 = 4; AccessRule accessRule1 = new AccessRule( ); AccessRule accessRule2 = new AccessRule( ); AccessRule accessRule3 = new AccessRule( ); Mock <IUserRoleRepository> mockRoles = new Mock <IUserRoleRepository>(MockBehavior.Strict); Mock <IRuleRepository> mockRules = new Mock <IRuleRepository>(MockBehavior.Strict); mockRoles.Setup(x => x.GetUserRoles(user1)).Returns(new HashSet <long> { role1, role2 }); mockRoles.Setup(x => x.GetUserRoles(user2)).Returns(new HashSet <long> { role1, role2 }); mockRules.Setup(x => x.GetAccessRules(user1, Permissions.Read, null)).Returns(new List <AccessRule> { }); mockRules.Setup(x => x.GetAccessRules(user2, Permissions.Read, null)).Returns(new List <AccessRule> { }); mockRules.Setup(x => x.GetAccessRules(role1, Permissions.Read, null)).Returns(new List <AccessRule> { accessRule1 }); mockRules.Setup(x => x.GetAccessRules(role2, Permissions.Read, null)).Returns(new List <AccessRule> { accessRule2, accessRule3 }); UserRuleSetProvider userRuleSetprovider = new UserRuleSetProvider(mockRoles.Object, mockRules.Object); UserRuleSet userRuleSet1 = userRuleSetprovider.GetUserRuleSet(user1, Permissions.Read); UserRuleSet userRuleSet2 = userRuleSetprovider.GetUserRuleSet(user2, Permissions.Read); Assert.That(userRuleSet1, Is.EqualTo(userRuleSet2)); Assert.That(userRuleSet1.GetHashCode( ), Is.EqualTo(userRuleSet2.GetHashCode( ))); }