Exemple #1
0
        public void ExistsShouldReturnTrueWhenGroupWithNameExists()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Exists(MembershipTestData.GroupAdminRoleName, null);

            Assert.IsTrue(result);
        }
Exemple #2
0
        public void ExistsShouldReturnFalseWhenGroupWithNameExistsButIdIsGroupsOwnId()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Exists(MembershipTestData.UserRoleName, MembershipTestData.UserRoleId);

            Assert.IsFalse(result);
        }
Exemple #3
0
        public void IsUserInRoleShouldReturnFalseWhenUserIsInRoleButMembershipNotYetStarted()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.IsUserInRole(MembershipTestData.KarateManagerId, PlatformConstants.GROUPADMINROLE);

            Assert.IsFalse(result);
        }
Exemple #4
0
        public void IsUserInRoleShouldReturnFalseWhenUserIsInRoleButMembershipExpired()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.IsUserInRole(MembershipTestData.DivingManagerId, MembershipTestData.EditorRoleName);

            Assert.IsFalse(result);
        }
Exemple #5
0
        public void IsUserInRoleShouldReturnTrueWhenUserIsInRole()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.IsUserInRole(MembershipTestData.AdminId, PlatformConstants.ADMINROLE);

            Assert.IsTrue(result);
        }
Exemple #6
0
        public void IsUserInRoleShouldReturnFalseWhenUserIsNotInRole()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.IsUserInRole(MembershipTestData.AdminId, MembershipTestData.EditorRoleName);

            Assert.IsFalse(result);
        }
Exemple #7
0
        public void GetRoleShouldReturnRoleWhenAccessible()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Get(MembershipTestData.EditorRoleId);

            Assert.IsNotNull(result);
        }
Exemple #8
0
        public void IsUserInRolesShouldReturnTrueWhenUserIsInOneOfTheRoles()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.IsUserInRoles(MembershipTestData.AdminId, new string[] { PlatformConstants.ADMINROLE, PlatformConstants.GROUPADMINROLE });

            Assert.IsTrue(result);
        }
Exemple #9
0
        public void AddGroupToNewRoleShouldSaveNewGroupInRoleEntity()
        {
            var mock = new RoleManagerMock();

            mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleName);
            mock.DataSourceMock.Mock.Verify(m => m.Save <GroupInRole>(It.IsAny <GroupInRole>()), Times.Once());
        }
Exemple #10
0
        public void GetAllRolesShouldReturnAllRolesExceptAdminRoleForCurrentAppForOtherGroups()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Query();

            Assert.AreEqual(3, result.Count());
        }
Exemple #11
0
        public void AddGroupToNewRoleWithInitialDateTimesShouldSetCorrectDatesAndSaveNewGroupInRoleEntity()
        {
            var mock = new RoleManagerMock();

            mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleName, new DateTime(), new DateTime());
            mock.DataSourceMock.Mock.Verify(m => m.Save <GroupInRole>(It.Is <GroupInRole>(g => g.StartDate != new DateTime() && g.EndDate != new DateTime())), Times.Once());
        }
Exemple #12
0
        public void RemoveGroupFromRoleShouldRemoveGroupInRoleEntity()
        {
            var mock = new RoleManagerMock();

            mock.RoleManager.RemoveGroupFromRoles(MembershipTestData.KarateGroupId, new string[] { MembershipTestData.GroupAdminRoleName });
            mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny <IEnumerable <GroupInRole> >()), Times.Once());
        }
Exemple #13
0
        public void ExistsShouldReturnFalseWhenGroupWithNameDoesNotExist()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Exists("Test", null);

            Assert.IsFalse(result);
        }
Exemple #14
0
        public void AddMainGroupToAdminRoleIsAllowed()
        {
            var mock = new RoleManagerMock();

            _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
            mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.AdminRoleName);
            _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
        }
 public void GroupUsesPermissionsShouldReturnTrueWhenGroupUsesPermissions()
 {
     var mock = new RoleManagerMock();
     var group = mock.DataSourceMock.DataList<Group>().First(g => g.Id == MembershipTestData.DivingGroupId);
     group.UsePermissions = true;
     var result = mock.RoleManager.GroupUsesPermissions(MembershipTestData.DivingGroupId);
     Assert.IsTrue(result);
 }
Exemple #16
0
        public void CreateShouldReturnExistingRoleWhenARoleAlreadyExists()
        {
            var mock   = new RoleManagerMock();
            var result = mock.RoleManager.Create(MembershipTestData.GroupAdminRoleName, "test", new List <Permission> {
                new Permission("one"), new Permission("two")
            });

            Assert.IsNotNull(result);
        }
Exemple #17
0
        public void AddUserToExistingRoleWithStartDateBeforeStartDateOfGroupShouldSetStartDateToGroupStartDate()
        {
            var mock      = new RoleManagerMock();
            var startDate = DateTime.Now;
            var userRole  = mock.DataSourceMock.DataList <UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.GroupAdminRoleId);

            mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.GroupAdminRole.Name, startDate);
            Assert.AreNotEqual(startDate, userRole.StartDate);
        }
Exemple #18
0
        public void AddUserToNewRoleShouldSaveNewUserInRoleEntity()
        {
            var mock      = new RoleManagerMock();
            var groupRole = new GroupInRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleId);

            mock.DataSourceMock.AddDataItem <GroupInRole>(groupRole);
            mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.UserRole.Name);
            mock.DataSourceMock.Mock.Verify(m => m.Save <UserInRole>(It.IsAny <UserInRole>()), Times.Once());
        }
Exemple #19
0
        public void DeleteRoleShouldHitDataSourceDeleteWhenDeletingAccessibleNonAdminRole()
        {
            var mock = new RoleManagerMock();

            _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId);
            mock.RoleManager.Delete(MembershipTestData.DivingPermissionSetRoleId);
            _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId);
            mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny <Role>()), Times.Once());
        }
Exemple #20
0
        public void DeleteRoleShouldNotHitDataSourceDeleteWhenDeletingAdminRole()
        {
            var mock = new RoleManagerMock();

            _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
            mock.RoleManager.Delete(MembershipTestData.AdminRoleId);
            _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
            mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny <Role>()), Times.Never());
        }
Exemple #21
0
        public void GetRolesForUserShouldReturnAllRolesForUser()
        {
            var mock = new RoleManagerMock();

            mock.FixRelations();
            var result = mock.RoleManager.QueryForUser(MembershipTestData.DivingManagerId);

            Assert.AreEqual(2, result.Count());
        }
Exemple #22
0
        public void AddGroupToExistingRoleWithNullStartDateShouldNotUpdateStartDateInGroupInRoleEntity()
        {
            var mock      = new RoleManagerMock();
            var startDate = DateTime.Now;
            var groupRole = mock.DataSourceMock.DataList <GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);

            mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.GroupAdminRoleName);
            Assert.AreNotEqual(startDate.Date, groupRole.StartDate.Date);
        }
Exemple #23
0
        public void AddUserToRoleThatNoMoreLicensesAreAvailableForShouldThrowException()
        {
            var mock = new RoleManagerMock();
            var role = mock.DataSourceMock.DataList <GroupInRole>().First(g => g.GroupId == MembershipTestData.DivingGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);

            role.MaxNumberOfUsers     = 2;
            role.CurrentNumberOfUsers = 2;
            mock.RoleManager.AddUserToRole(MembershipTestData.DivingGroupId, MembershipTestData.GeneralManagerId, MembershipTestData.GroupAdminRoleName);
        }
Exemple #24
0
        public void AddUserToExistingRoleShouldUpdateUserInRoleEntity()
        {
            var mock      = new RoleManagerMock();
            var startDate = DateTime.Now;
            var userRole  = mock.DataSourceMock.DataList <UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.GroupAdminRoleId);

            mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.GroupAdminRoleName, startDate.AddDays(5), startDate.AddDays(10));
            Assert.AreEqual(startDate.AddDays(5), userRole.StartDate);
            Assert.AreEqual(startDate.AddDays(10), userRole.EndDate);
        }
Exemple #25
0
        public void RemoveUserFromRoleShouldRemoveUserInRoleEntityAndUpdateGroupInRoleUserCount()
        {
            var mock        = new RoleManagerMock();
            var groupInRole = mock.DataSourceMock.DataList <GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);
            var oldCount    = groupInRole.CurrentNumberOfUsers;

            mock.RoleManager.RemoveUsersFromRoles(new Guid[] { MembershipTestData.KarateManagerId }, new string[] { MembershipTestData.GroupAdminRoleName });
            mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny <IEnumerable <UserInRole> >()), Times.Once());
            Assert.AreEqual(oldCount - 1, groupInRole.CurrentNumberOfUsers);
        }
Exemple #26
0
        public void GroupUsesPermissionsShouldReturnTrueWhenGroupUsesPermissions()
        {
            var mock  = new RoleManagerMock();
            var group = mock.DataSourceMock.DataList <Group>().First(g => g.Id == MembershipTestData.DivingGroupId);

            group.UsePermissions = true;
            var result = mock.RoleManager.GroupUsesPermissions(MembershipTestData.DivingGroupId);

            Assert.IsTrue(result);
        }
 public void GetPermissionSetForGroupShouldReturnProperPermissionSet()
 {
     var mock = new RoleManagerMock();
     var role = mock.DataSourceMock.DataList<Role>().First(r => r.Id == MembershipTestData.DivingPermissionSetRoleId);
     role.Groups.Add(MembershipTestData.DivingGroupPermissionSet);
     var result = mock.RoleManager.GetPermissionSetForGroup(MembershipTestData.DivingGroupId);
     Assert.IsNotNull(result);
     Assert.AreEqual(MembershipTestData.DivingGroupId, result.GroupId);
     Assert.AreEqual(Resources.DefaultValues.PermissionSetName, result.Role.Name);
 }
Exemple #28
0
        public void GetAllRolesShouldReturnAllRolesForCurrentAppForMainGroup()
        {
            var mock = new RoleManagerMock();

            _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
            var result = mock.RoleManager.Query().ToList();

            _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
            Assert.AreEqual(3, result.Count());
        }
Exemple #29
0
        public void GetRolesForGroupShouldReturnAllRolesForGroup()
        {
            var mock = new RoleManagerMock();

            mock.DataSourceMock.RegisterData <Group>(MembershipTestData.Groups);
            mock.FixRelations();
            var result = mock.RoleManager.QueryForGroup(MembershipTestData.DivingGroupId);

            Assert.AreEqual(2, result.Count());
        }
 public void CreateShouldReturnTrueWhenANewRoleIsAddedWithDescriptionAndPermissions()
 {
     var mock = new RoleManagerMock();
     mock.DataSourceMock.Mock.Setup(m => m.Save(It.IsAny<Role>())).Returns<Role>(r => r);
     var result = mock.RoleManager.Create("Test B", "test", new List<Permission> { new Permission("one"), new Permission("two") });
     Assert.IsNotNull(result);
     Assert.AreEqual("test", result.Description);
     Assert.AreEqual(2, result.Permissions.Count);
     mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny<Role>()), Times.Once());
 }
Exemple #31
0
        public void AddMainGroupUserToRoleThatNoGroupRecordExistsForShouldAddThatRecord()
        {
            var mock = new RoleManagerMock();

            _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
            mock.RoleManager.AddUserToRole(MembershipTestData.MainGroupId, MembershipTestData.GeneralManagerId, MembershipTestData.UserRoleName);
            _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
            mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny <GroupInRole>()), Times.Once());
            mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny <UserInRole>()), Times.Once());
        }
Exemple #32
0
        public void AddUserToExistingRoleWithoutEndDateWhileGroupHasAnEndDateShouldSetEndDateToGroupEndDate()
        {
            var mock      = new RoleManagerMock();
            var groupRole = mock.DataSourceMock.DataList <GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.EditorRoleId);

            groupRole.EndDate = DateTime.Now.AddDays(3);
            var userRole = mock.DataSourceMock.DataList <UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.EditorRoleId);

            mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.EditorRoleName, null, null);
            Assert.AreEqual(groupRole.EndDate, userRole.EndDate);
        }
Exemple #33
0
        public void GetPermissionSetForGroupShouldReturnProperPermissionSet()
        {
            var mock = new RoleManagerMock();
            var role = mock.DataSourceMock.DataList <Role>().First(r => r.Id == MembershipTestData.DivingPermissionSetRoleId);

            role.Groups.Add(MembershipTestData.DivingGroupPermissionSet);
            var result = mock.RoleManager.GetPermissionSetForGroup(MembershipTestData.DivingGroupId);

            Assert.IsNotNull(result);
            Assert.AreEqual(MembershipTestData.DivingGroupId, result.GroupId);
            Assert.AreEqual(Resources.DefaultValues.PermissionSetName, result.Role.Name);
        }
 public void AddUserToNewRoleShouldSaveNewUserInRoleEntity()
 {
     var mock = new RoleManagerMock();
     var groupRole = new GroupInRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleId);
     mock.DataSourceMock.AddDataItem<GroupInRole>(groupRole);
     mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.UserRole.Name);
     mock.DataSourceMock.Mock.Verify(m => m.Save<UserInRole>(It.IsAny<UserInRole>()), Times.Once());
 }
 public void AddUserToExistingRoleWithoutEndDateWhileGroupHasAnEndDateShouldSetEndDateToGroupEndDate()
 {
     var mock = new RoleManagerMock();
     var groupRole = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.EditorRoleId);
     groupRole.EndDate = DateTime.Now.AddDays(3);
     var userRole = mock.DataSourceMock.DataList<UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.EditorRoleId);
     mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.EditorRoleName, null, null);
     Assert.AreEqual(groupRole.EndDate, userRole.EndDate);
 }
 public void AddUserToRoleThatNoMoreLicensesAreAvailableForShouldThrowException()
 {
     var mock = new RoleManagerMock();
     var role = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.DivingGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);
     role.MaxNumberOfUsers = 2;
     role.CurrentNumberOfUsers = 2;
     mock.RoleManager.AddUserToRole(MembershipTestData.DivingGroupId, MembershipTestData.GeneralManagerId, MembershipTestData.GroupAdminRoleName);
 }
 public void AddUserToRoleThatHisGroupHasNoAccessToShouldThrowException()
 {
     var mock = new RoleManagerMock();
     mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.AdminRoleName);
 }
 public void IsUserInRolesShouldReturnTrueWhenUserIsInOneOfTheRoles()
 {
     var mock = new RoleManagerMock();
     var result = mock.RoleManager.IsUserInRoles(MembershipTestData.AdminId, new string[] { PlatformConstants.ADMINROLE, PlatformConstants.GROUPADMINROLE });
     Assert.IsTrue(result);
 }
 public void UpdateShouldUpdateTheRoleDescriptionAndPermissionsAndHitSave()
 {
     var mock = new RoleManagerMock();
     mock.DataSourceMock.Mock.Setup(m => m.Save(It.IsAny<Role>())).Returns<Role>(r => r);
     var result = mock.RoleManager.Update(MembershipTestData.GroupAdminRoleId, "test", "test", new List<Permission> { new Permission("one"), new Permission("two") });
     Assert.IsNotNull(result);
     Assert.AreEqual("test", result.Description);
     Assert.AreEqual(2, result.Permissions.Count);
     mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny<Role>()), Times.Once());
 }
 public void CreateShouldReturnExistingRoleWhenARoleAlreadyExists()
 {
     var mock = new RoleManagerMock();
     var result = mock.RoleManager.Create(MembershipTestData.GroupAdminRoleName, "test", new List<Permission> { new Permission("one"), new Permission("two") });
     Assert.IsNotNull(result);
 }
 public void GetRolesForUserShouldReturnAllRolesForUser()
 {
     var mock = new RoleManagerMock();
     mock.FixRelations();
     var result = mock.RoleManager.QueryForUser(MembershipTestData.DivingManagerId);
     Assert.AreEqual(2, result.Count());
 }
 public void GetAllRolesShouldReturnAllRolesForCurrentAppForMainGroup()
 {
     var mock = new RoleManagerMock();
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
     var result = mock.RoleManager.Query().ToList();
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
     Assert.AreEqual(3, result.Count());
 }
 public void AddUserToExistingRoleWithStartDateBeforeStartDateOfGroupShouldSetStartDateToGroupStartDate()
 {
     var mock = new RoleManagerMock();
     var startDate = DateTime.Now;
     var userRole = mock.DataSourceMock.DataList<UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.GroupAdminRoleId);
     mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.GroupAdminRole.Name, startDate);
     Assert.AreNotEqual(startDate, userRole.StartDate);
 }
 public void AddGroupToNewRoleWithInitialDateTimesShouldSetCorrectDatesAndSaveNewGroupInRoleEntity()
 {
     var mock = new RoleManagerMock();
     mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleName, new DateTime(), new DateTime());
     mock.DataSourceMock.Mock.Verify(m => m.Save<GroupInRole>(It.Is<GroupInRole>(g => g.StartDate != new DateTime() && g.EndDate != new DateTime())), Times.Once());
 }
 public void AddGroupToExistingRoleWithNullStartDateShouldNotUpdateStartDateInGroupInRoleEntity()
 {
     var mock = new RoleManagerMock();
     var startDate = DateTime.Now;
     var groupRole = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);
     mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.GroupAdminRoleName);
     Assert.AreNotEqual(startDate.Date, groupRole.StartDate.Date);
 }
 public void AddGroupToNewRoleShouldSaveNewGroupInRoleEntity()
 {
     var mock = new RoleManagerMock();
     mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.UserRoleName);
     mock.DataSourceMock.Mock.Verify(m => m.Save<GroupInRole>(It.IsAny<GroupInRole>()), Times.Once());
 }
 public void GetRolesForGroupShouldReturnAllRolesForGroup()
 {
     var mock = new RoleManagerMock();
     mock.DataSourceMock.RegisterData<Group>(MembershipTestData.Groups);
     mock.FixRelations();
     var result = mock.RoleManager.QueryForGroup(MembershipTestData.DivingGroupId);
     Assert.AreEqual(2, result.Count());
 }
 public void RemoveGroupFromRoleShouldRemoveGroupInRoleEntity()
 {
     var mock = new RoleManagerMock();
     mock.RoleManager.RemoveGroupFromRoles(MembershipTestData.KarateGroupId, new string[] { MembershipTestData.GroupAdminRoleName });
     mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny<IEnumerable<GroupInRole>>()), Times.Once());
 }
 public void GetAllRolesShouldReturnAllRolesExceptAdminRoleForCurrentAppForOtherGroups()
 {
     var mock = new RoleManagerMock();
     var result = mock.RoleManager.Query();
     Assert.AreEqual(3, result.Count());
 }
 public void RemoveUserFromRoleShouldRemoveUserInRoleEntityAndUpdateGroupInRoleUserCount()
 {
     var mock = new RoleManagerMock();
     var groupInRole = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);
     var oldCount = groupInRole.CurrentNumberOfUsers;
     mock.RoleManager.RemoveUsersFromRoles(new Guid[] { MembershipTestData.KarateManagerId }, new string[] { MembershipTestData.GroupAdminRoleName });
     mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny<IEnumerable<UserInRole>>()), Times.Once());
     Assert.AreEqual(oldCount - 1, groupInRole.CurrentNumberOfUsers);
 }
 public void AddNonMainGroupToAdminRoleShouldThrowException()
 {
     var mock = new RoleManagerMock();
     mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.AdminRoleName);
 }
 public void AddMainGroupToAdminRoleIsAllowed()
 {
     var mock = new RoleManagerMock();
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
     mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.AdminRoleName);
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
 }
        public void AddGroupToExistingRoleWithLaterStartDateAndEarlierEndDateShouldUpdateStartDateAndEndDatesForUserEntries()
        {
            var mock = new RoleManagerMock();
            var groupRole = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.KarateGroupId && g.RoleId == MembershipTestData.GroupAdminRoleId);
            var userRoles = mock.DataSourceMock.DataList<User>().SelectMany(u => u.Roles).Where(g => g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.GroupAdminRoleId).ToList();
            var newStartDate = groupRole.StartDate.AddDays(2);
            var newEndDate = groupRole.EndDate.Value.AddDays(-2);

            mock.RoleManager.AddGroupToRole(MembershipTestData.KarateGroupId, MembershipTestData.GroupAdminRoleName, newStartDate, newEndDate);

            foreach (var entry in userRoles)
            {
                Assert.AreEqual(newStartDate, entry.StartDate);
                Assert.AreEqual(newEndDate, entry.EndDate);
            }
        }
 public void AddUserToExistingRoleShouldUpdateUserInRoleEntity()
 {
     var mock = new RoleManagerMock();
     var startDate = DateTime.Now;
     var userRole = mock.DataSourceMock.DataList<UserInRole>().First(g => g.UserId == MembershipTestData.KarateManagerId && g.GroupRoleGroupId == MembershipTestData.KarateGroupId && g.GroupRoleRoleId == MembershipTestData.GroupAdminRoleId);
     mock.RoleManager.AddUserToRole(MembershipTestData.KarateGroupId, MembershipTestData.KarateManagerId, MembershipTestData.GroupAdminRoleName, startDate.AddDays(5), startDate.AddDays(10));
     Assert.AreEqual(startDate.AddDays(5), userRole.StartDate);
     Assert.AreEqual(startDate.AddDays(10), userRole.EndDate);
 }
 public void AddGroupToExistingRoleWithEarlierStartDateAndLaterEndDateShouldUpdateStartDateAndEndDatesForUserEntriesWithMatchingStartOrEndDates()
 {
     var mock = new RoleManagerMock();
     var groupRole = mock.DataSourceMock.DataList<GroupInRole>().First(g => g.GroupId == MembershipTestData.DivingGroupId && g.RoleId == MembershipTestData.EditorRoleId);
     var userRoles = mock.DataSourceMock.DataList<User>().SelectMany(u => u.Roles).Where(g => g.GroupRoleGroupId == MembershipTestData.DivingGroupId && g.GroupRoleRoleId == MembershipTestData.EditorRoleId).ToList();
     userRoles.First().StartDate = groupRole.StartDate;
     userRoles.First().EndDate = groupRole.EndDate.Value.AddDays(-5);
     userRoles.Last().StartDate = groupRole.StartDate.AddDays(2);
     userRoles.Last().EndDate = groupRole.EndDate;
     var newStartDate = groupRole.StartDate.AddDays(-2);
     var newEndDate = groupRole.EndDate.Value.AddDays(2);
     mock.RoleManager.AddGroupToRole(MembershipTestData.DivingGroupId, MembershipTestData.EditorRoleName, newStartDate, newEndDate);
     Assert.AreEqual(userRoles.First().StartDate, groupRole.StartDate);
     Assert.AreNotEqual(userRoles.First().EndDate, groupRole.EndDate);
     Assert.AreNotEqual(userRoles.Last().StartDate, groupRole.StartDate);
     Assert.AreEqual(userRoles.Last().EndDate, groupRole.EndDate);
 }
 public void DeleteRoleShouldNotHitDataSourceDeleteWhenDeletingAdminRole()
 {
     var mock = new RoleManagerMock();
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
     mock.RoleManager.Delete(MembershipTestData.AdminRoleId);
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
     mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny<Role>()), Times.Never());
 }
 public void GetRoleShouldReturnRoleWhenAccessible()
 {
     var mock = new RoleManagerMock();
     var result = mock.RoleManager.Get(MembershipTestData.EditorRoleId);
     Assert.IsNotNull(result);
 }
 public void DeleteRoleShouldHitDataSourceDeleteWhenDeletingAccessibleNonAdminRole()
 {
     var mock = new RoleManagerMock();
     _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId);
     mock.RoleManager.Delete(MembershipTestData.DivingPermissionSetRoleId);
     _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId);
     mock.DataSourceMock.Mock.Verify(m => m.Delete(It.IsAny<Role>()), Times.Once());
 }
 public void IsUserInRoleShouldReturnTrueWhenUserIsInRole()
 {
     var mock = new RoleManagerMock();
     var result = mock.RoleManager.IsUserInRole(MembershipTestData.AdminId, PlatformConstants.ADMINROLE);
     Assert.IsTrue(result);
 }
 public void AddMainGroupUserToRoleThatNoGroupRecordExistsForShouldAddThatRecord()
 {
     var mock = new RoleManagerMock();
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(true);
     mock.RoleManager.AddUserToRole(MembershipTestData.MainGroupId, MembershipTestData.GeneralManagerId, MembershipTestData.UserRoleName);
     _userContextMock.Setup(m => m.IsInMainGroup).Returns(false);
     mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny<GroupInRole>()), Times.Once());
     mock.DataSourceMock.Mock.Verify(m => m.Save(It.IsAny<UserInRole>()), Times.Once());
 }