public void GetShouldRetrieveFilledGroupModelForUsingPermissions() { var mock = new GroupServiceMock(); mock.DataSourceMock.Setup(m => m.Query <Group>()).Returns(MembershipTestData.Groups.AsQueryable()); mock.GroupManagerMock.Setup(g => g.Get(MembershipTestData.DivingGroupId)).Returns(MembershipTestData.DivingGroup); mock.RoleManagerMock.Setup(r => r.Query()).Returns(MembershipTestData.Roles.Where(r => r.Permissions.Any(p => p.ApplicationId == MembershipTestData.AppId)).AsQueryable()); var groupRoles = MembershipTestData.GroupsInRoles; var groupInRole = new GroupInRole(MembershipTestData.DivingGroupId, MembershipTestData.DivingPermissionSetRoleId); groupInRole.Role = MembershipTestData.DivingPermissionSetRole; groupRoles.Add(groupInRole); var groupRoleQuery = groupRoles.Where(g => g.GroupId == MembershipTestData.DivingGroupId).Select(g => g.Role).Map <AssignRoleModel>().AsQueryable(); mock.RoleManagerMock.Setup(r => r.QueryForGroup(MembershipTestData.DivingGroupId)).Returns(groupRoleQuery); mock.RoleManagerMock.Setup(p => p.PermissionQuery()).Returns(MembershipTestData.Permissions.Where(p => p.ApplicationId == MembershipTestData.AppId).AsQueryable()); mock.RoleManagerMock.Setup(p => p.GetPermissionSetForGroup(MembershipTestData.DivingGroupId)).Returns(groupInRole); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId); var result = mock.GroupService.Get(MembershipTestData.DivingGroupId); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId); Assert.IsNotNull(result); Assert.AreEqual(5, result.Roles.Count); Assert.AreEqual(2, result.Roles.Where(r => r.Selected).Count()); Assert.AreEqual(4, result.Permissions.Count); Assert.AreEqual(1, result.Permissions.Where(r => r.Selected).Count()); Assert.AreEqual(MembershipTestData.CreateUserPermission.Name, result.Permissions.First(r => r.Selected).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 GetShouldRetrieveFilledGroupModelForUsingPermissions() { var mock = new GroupServiceMock(); mock.DataSourceMock.Setup(m => m.Query<Group>()).Returns(MembershipTestData.Groups.AsQueryable()); mock.GroupManagerMock.Setup(g => g.Get(MembershipTestData.DivingGroupId)).Returns(MembershipTestData.DivingGroup); mock.RoleManagerMock.Setup(r => r.Query()).Returns(MembershipTestData.Roles.Where(r => r.Permissions.Any(p => p.ApplicationId == MembershipTestData.AppId)).AsQueryable()); var groupRoles = MembershipTestData.GroupsInRoles; var groupInRole = new GroupInRole(MembershipTestData.DivingGroupId, MembershipTestData.DivingPermissionSetRoleId); groupInRole.Role = MembershipTestData.DivingPermissionSetRole; groupRoles.Add(groupInRole); var groupRoleQuery = groupRoles.Where(g => g.GroupId == MembershipTestData.DivingGroupId).Select(g => g.Role).Map<AssignRoleModel>().AsQueryable(); mock.RoleManagerMock.Setup(r => r.QueryForGroup(MembershipTestData.DivingGroupId)).Returns(groupRoleQuery); mock.RoleManagerMock.Setup(p => p.PermissionQuery()).Returns(MembershipTestData.Permissions.Where(p => p.ApplicationId == MembershipTestData.AppId).AsQueryable()); mock.RoleManagerMock.Setup(p => p.GetPermissionSetForGroup(MembershipTestData.DivingGroupId)).Returns(groupInRole); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId); var result = mock.GroupService.Get(MembershipTestData.DivingGroupId); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId); Assert.IsNotNull(result); Assert.AreEqual(5, result.Roles.Count); Assert.AreEqual(2, result.Roles.Where(r => r.Selected).Count()); Assert.AreEqual(4, result.Permissions.Count); Assert.AreEqual(1, result.Permissions.Where(r => r.Selected).Count()); Assert.AreEqual(MembershipTestData.CreateUserPermission.Name, result.Permissions.First(r => r.Selected).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()); }