public void PortalSecurity_IsInRoles_NonAdminUser_True_WhenRoleIsFollowerRoleAndRoleEntityIsFollowedByUser() { // Arrange var user = new UserInfo { IsSuperUser = false, UserID = Constants.USER_TenId }; var relatedUser = new UserInfo { IsSuperUser = false, UserID = Constants.USER_ValidId }; string roles = "FOLLOWER:" + relatedUser.UserID; var mockUserController = new Mock <IUserController>(); mockUserController.Setup(uc => uc.GetUserById(It.IsAny <int>(), Constants.USER_ValidId)).Returns(relatedUser); UserController.SetTestableInstance(mockUserController.Object); var mockRelationShipController = new Mock <IRelationshipController>(); mockRelationShipController.Setup( rsc => rsc.GetFollowerRelationship(It.Is <UserInfo>(u => u.UserID == Constants.USER_TenId), It.Is <UserInfo>(u => u.UserID == Constants.USER_ValidId))) .Returns(new UserRelationship() { Status = RelationshipStatus.Accepted }); RelationshipController.SetTestableInstance(mockRelationShipController.Object); var portalSettings = SetupPortalSettings(); // Act and Assert Assert.IsTrue(PortalSecurity.IsInRoles(user, portalSettings, roles)); }
public void PortalSecurity_IsInRoles_NonAdminUser_False_WhenRoleIsFriendRoleAndRoleEntityIsNotFriend() { // Arrange var user = new UserInfo { IsSuperUser = false, UserID = Constants.USER_TenId }; var relatedUser = new UserInfo { IsSuperUser = false, UserID = Constants.USER_ValidId }; string roles = "FRIEND:" + relatedUser.UserID; var mockUserController = new Mock <IUserController>(); mockUserController.Setup(uc => uc.GetUserById(It.IsAny <int>(), Constants.USER_ValidId)).Returns(relatedUser); UserController.SetTestableInstance(mockUserController.Object); var mockRelationShipController = new Mock <IRelationshipController>(); mockRelationShipController.Setup( rsc => rsc.GetFriendRelationship(It.Is <UserInfo>(u => u.UserID == Constants.USER_TenId), It.Is <UserInfo>(u => u.UserID == Constants.USER_ValidId))) .Returns(() => null); RelationshipController.SetTestableInstance(mockRelationShipController.Object); var portalSettings = SetupPortalSettings(); // Act and Assert Assert.IsFalse(PortalSecurity.IsInRoles(user, portalSettings, roles)); }