public void GetOrderedListForLockedOutShouldReturnAnOrderedList() { var mock = new UserServiceMock(); var userSecurity = MembershipTestData.UserSecurity; var entry = userSecurity.First(s => s.Id == MembershipTestData.GeneralManagerId); entry.LockedOut = true; mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.DataSourceMock.Setup(d => d.Query <UserSecurity>()).Returns(userSecurity.AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny <Guid[]>())).Returns(new List <AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false }, new AccountStatus { Id = MembershipTestData.GeneralManagerId, Approved = true, LockedOut = false } }); var sortFields = new List <SortField>(); sortFields.Add(new SortField { Field = "LockedOut", Dir = "desc" }); var result = mock.UserService.List(new FilterOptions { Sort = sortFields }); Assert.AreEqual(2, result.Length()); Assert.AreEqual(MembershipTestData.AdminName, result.Cast <UserListModel>().Last().Name); }
public void SavingAnExistingUserWithANewEmailAndNewRolesShouldSendEmailChangedMailAndUpdateRoles() { var mock = new UserServiceMock(); var user = MembershipTestData.GeneralManager; mock.UserManagerMock.Setup(m => m.Update(MembershipTestData.GeneralManagerId, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(user); mock.UserManagerMock.Setup(m => m.GetEmail(user.Id)).Returns(user.Email); mock.MailerMock.Setup(m => m.SendEmailChangedMail("en", "Rutger", "test", user.Email)).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(user.Id)).Returns(MembershipTestData.UsersInRoles.Map <AssignRoleModel>().AsQueryable()); var model = user.Map <UserViewModel>(); model.Email = "Test"; model.Roles = new List <AssignRoleModel>() { new AssignRoleModel { Name = "Manager", Selected = true }, new AssignRoleModel { Name = "User", Selected = true } }; var result = mock.UserService.Save(model); Assert.IsTrue(result.Success); Assert.IsNull(result.Message); Assert.IsNotNull(result.Model); mock.RoleManagerMock.Verify(r => r.AddUserToRole(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>()), Times.Exactly(2)); mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(1)); }
public void GetShouldReturnUserViewModelWithRolesAndSecurityData() { var mock = new UserServiceMock(); var groupStartDate = DateTime.Now.AddDays(-20); var groupEndDate = DateTime.Now.AddDays(40); var startDate = DateTime.Now.AddDays(-10); var endDate = DateTime.Now.AddDays(20); mock.RoleManagerMock.Setup(r => r.QueryForGroup(MembershipTestData.MainGroupId)).Returns(MembershipTestData.GroupsInRoles.Where(g => g.GroupId == MembershipTestData.MainGroupId).Select(g => new AssignRoleModel { Id = g.RoleId, Name = g.Role.Name, StartDate = groupStartDate, EndDate = groupEndDate }).AsQueryable()); mock.RoleManagerMock.Setup(r => r.QueryForUser(MembershipTestData.AdminId)).Returns(MembershipTestData.UsersInRoles.Where(g => g.UserId == MembershipTestData.AdminId).Select(g => new AssignRoleModel { Id = g.GroupRole.RoleId, Name = g.GroupRole.Role.Name, StartDate = startDate, EndDate = endDate }).AsQueryable()); var result = mock.UserService.Get(MembershipTestData.AdminId); Assert.IsNotNull(result); Assert.AreEqual(2, result.Roles.Count); Assert.AreEqual(1, result.Roles.Count(r => r.Selected)); Assert.AreEqual(groupStartDate, result.Roles[0].GroupStartDate); Assert.AreEqual(groupEndDate, result.Roles[0].GroupEndDate); Assert.AreEqual(startDate, result.Roles[0].StartDate); Assert.AreEqual(endDate, result.Roles[0].EndDate); Assert.IsTrue(result.Approved); Assert.IsFalse(result.LockedOut); }
public void GetApprovedListShouldReturnOnlyEntriesThatAreApproved() { var mock = new UserServiceMock(); var userSecurity = MembershipTestData.UserSecurity; var entry = userSecurity.First(s => s.Id == MembershipTestData.GeneralManagerId); entry.Approved = false; mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.DataSourceMock.Setup(d => d.Query <UserSecurity>()).Returns(userSecurity.AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny <Guid[]>())).Returns(new List <AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false } }); var result = mock.UserService.List(new FilterOptions { Filter = new Filter { Filters = new List <FilterField> { new FilterField { Field = "Approved", Value = "true" } } } }); Assert.AreEqual(1, result.Length()); Assert.AreEqual(MembershipTestData.AdminName, (result.GetFirst() as UserListModel).Name); }
public void GetFilteredListShouldReturnOnlyEntriesThatMatchTheFilter() { var mock = new UserServiceMock(); mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny<Guid[]>())).Returns(new List<AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false } }); var result = mock.UserService.List(new FilterOptions { Filter = new Filter { Filters = new List<FilterField> { new FilterField { Field = "Name", Value = "Ad" } } } }); Assert.AreEqual(1, result.Length()); Assert.AreEqual(MembershipTestData.AdminName, (result.GetFirst() as UserListModel).Name); }
public void AGroupAdministratorCannotDeleteAnAdministrator() { var mock = new UserServiceMock(); _userContextMock.Setup(m => m.IsInRole(PlatformConstants.GROUPADMINROLE)).Returns(true); mock.RoleManagerMock.Setup(r => r.IsUserInRole(MembershipTestData.AdminId, PlatformConstants.ADMINROLE)).Returns(true); mock.UserService.Delete(MembershipTestData.AdminId); _userContextMock.Setup(m => m.IsInRole(PlatformConstants.GROUPADMINROLE)).Returns(false); }
public void GetListShouldReturnListOfUsersWithSecurityData() { var mock = new UserServiceMock(); mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny<Guid[]>())).Returns(new List<AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false }, new AccountStatus { Id = MembershipTestData.GeneralManagerId, Approved = true, LockedOut = false } }); var result = mock.UserService.List(null).AsQueryable(); Assert.AreEqual(2, result.Length()); Assert.AreEqual(2, result.Where("Approved && !LockedOut").Length()); }
public void GetUserProfileShouldReturnProfileWithAllData() { var mock = new UserServiceMock(); mock.UserManagerMock.Setup(u => u.ProfileQuery()).Returns(MembershipTestData.Profiles.AsQueryable()); var result = mock.UserService.GetProfile(MembershipTestData.AdminId); Assert.AreEqual(new DateTime(1980, 8, 26), result.BirthDate); Assert.AreEqual("Leusden", result.City); Assert.AreEqual(5, result.Stars); }
public void SavingANewUserShouldCreateTheUserWithAGeneratedPasswordAndSendInformationMail() { var mock = new UserServiceMock(); var model = GetUserModel(mock); var result = mock.UserService.Save(model); Assert.IsTrue(result.Success); Assert.IsNull(result.Message); Assert.IsNotNull(result.Model); mock.SecurityManagerMock.Verify(m => m.GeneratePassword(), Times.Once()); mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(1)); }
private UserViewModel GetUserModel(UserServiceMock mock) { var user = new User(Guid.Empty, "*****@*****.**", "Rutger"); user.PreferredCulture = "en"; mock.UserManagerMock.Setup(m => m.Create("Rutger", "*****@*****.**", "en", It.IsAny <string>(), true, false, It.IsAny <string>())).Returns(user); mock.MailerMock.Setup(m => m.SendAccountInformationMail("en", "Rutger", "*****@*****.**", It.IsAny <Guid>())).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(It.IsAny <Guid>())).Returns(new List <AssignRoleModel>().AsQueryable()); var model = user.Map <UserViewModel>(); model.Roles = new List <AssignRoleModel>(); return(model); }
public void DeletingAUserForAGroupThatUsesPermissionsShouldLowerTheLicenseCountForThePermissionSet() { var mock = new UserServiceMock(); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId); var permissionSet = MembershipTestData.DivingGroupPermissionSet; permissionSet.MaxNumberOfUsers = 2; permissionSet.CurrentNumberOfUsers = 2; mock.RoleManagerMock.Setup(m => m.GroupUsesPermissions(MembershipTestData.DivingGroupId)).Returns(true); mock.RoleManagerMock.Setup(m => m.GetPermissionSetForGroup(MembershipTestData.DivingGroupId)).Returns(permissionSet); mock.UserService.Delete(MembershipTestData.DivingManagerId); Assert.AreEqual(1, permissionSet.CurrentNumberOfUsers); }
public void SavingANewUserWhenUsingPermissionsAndNoMoreLicencesAreAvailableShouldReturnFalse() { var mock = new UserServiceMock(); var permissionSet = MembershipTestData.DivingGroupPermissionSet; permissionSet.MaxNumberOfUsers = 2; permissionSet.CurrentNumberOfUsers = 2; mock.RoleManagerMock.Setup(m => m.GroupUsesPermissions(MembershipTestData.DivingGroupId)).Returns(true); mock.RoleManagerMock.Setup(m => m.GetPermissionSetForGroup(MembershipTestData.DivingGroupId)).Returns(permissionSet); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId); var result = mock.UserService.Save(new UserViewModel()); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId); Assert.IsFalse(result.Success); }
public void GetListShouldReturnListOfUsersWithSecurityData() { var mock = new UserServiceMock(); mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny <Guid[]>())).Returns(new List <AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false }, new AccountStatus { Id = MembershipTestData.GeneralManagerId, Approved = true, LockedOut = false } }); var result = mock.UserService.List(null).AsQueryable(); Assert.AreEqual(2, result.Length()); Assert.AreEqual(2, result.Where("Approved && !LockedOut").Length()); }
public void SavingANewUserWhenUsingPermissionsShouldUpdatePermissionSetLicenseCount() { var mock = new UserServiceMock(); var permissionSet = MembershipTestData.DivingGroupPermissionSet; permissionSet.MaxNumberOfUsers = 5; permissionSet.CurrentNumberOfUsers = 2; mock.RoleManagerMock.Setup(m => m.GroupUsesPermissions(MembershipTestData.DivingGroupId)).Returns(true); mock.RoleManagerMock.Setup(m => m.GetPermissionSetForGroup(MembershipTestData.DivingGroupId)).Returns(permissionSet); var model = GetUserModel(mock); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.DivingGroupId); var result = mock.UserService.Save(model); _userContextMock.Setup(m => m.GroupId).Returns(MembershipTestData.MainGroupId); Assert.AreEqual(3, permissionSet.CurrentNumberOfUsers); }
public void SavingAnExistingUserWithExistingEmailShouldOnlyUpdateHisRoles() { var mock = new UserServiceMock(); var user = MembershipTestData.GeneralManager; mock.UserManagerMock.Setup(m => m.Update(MembershipTestData.GeneralManagerId, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(user); mock.UserManagerMock.Setup(m => m.GetEmail(user.Id)).Returns(user.Email); mock.MailerMock.Setup(m => m.SendAccountInformationMail("en", "Rutger", "*****@*****.**", It.IsAny <Guid>())).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(user.Id)).Returns(MembershipTestData.UsersInRoles.Map <AssignRoleModel>().AsQueryable()); var model = user.Map <UserViewModel>(); model.Roles = new List <AssignRoleModel>(); var result = mock.UserService.Save(user.Map <UserViewModel>()); Assert.IsTrue(result.Success); Assert.IsNull(result.Message); Assert.IsNotNull(result.Model); mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(1)); }
private UserViewModel GetUserModel(UserServiceMock mock) { var user = new User(Guid.Empty, "*****@*****.**", "Rutger"); user.PreferredCulture = "en"; mock.UserManagerMock.Setup(m => m.Create("Rutger", "*****@*****.**", "en", It.IsAny<string>(), true, false, It.IsAny<string>())).Returns(user); mock.MailerMock.Setup(m => m.SendAccountInformationMail("en", "Rutger", "*****@*****.**", It.IsAny<Guid>())).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(It.IsAny<Guid>())).Returns(new List<AssignRoleModel>().AsQueryable()); var model = user.Map<UserViewModel>(); model.Roles = new List<AssignRoleModel>(); return model; }
public void SavingAnExistingUserWithExistingEmailShouldOnlyUpdateHisRoles() { var mock = new UserServiceMock(); var user = MembershipTestData.GeneralManager; mock.UserManagerMock.Setup(m => m.Update(MembershipTestData.GeneralManagerId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(user); mock.UserManagerMock.Setup(m => m.GetEmail(user.Id)).Returns(user.Email); mock.MailerMock.Setup(m => m.SendAccountInformationMail("en", "Rutger", "*****@*****.**", It.IsAny<Guid>())).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(user.Id)).Returns(MembershipTestData.UsersInRoles.Map<AssignRoleModel>().AsQueryable()); var model = user.Map<UserViewModel>(); model.Roles = new List<AssignRoleModel>(); var result = mock.UserService.Save(user.Map<UserViewModel>()); Assert.IsTrue(result.Success); Assert.IsNull(result.Message); Assert.IsNotNull(result.Model); mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(1)); }
public void SavingAnExistingUserWithANewEmailAndNewRolesShouldSendEmailChangedMailAndUpdateRoles() { var mock = new UserServiceMock(); var user = MembershipTestData.GeneralManager; mock.UserManagerMock.Setup(m => m.Update(MembershipTestData.GeneralManagerId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(user); mock.UserManagerMock.Setup(m => m.GetEmail(user.Id)).Returns(user.Email); mock.MailerMock.Setup(m => m.SendEmailChangedMail("en", "Rutger", "test", user.Email)).Returns(true); mock.RoleManagerMock.Setup(m => m.QueryForUser(user.Id)).Returns(MembershipTestData.UsersInRoles.Map<AssignRoleModel>().AsQueryable()); var model = user.Map<UserViewModel>(); model.Email = "Test"; model.Roles = new List<AssignRoleModel>() { new AssignRoleModel { Name = "Manager", Selected = true }, new AssignRoleModel { Name = "User", Selected = true } }; var result = mock.UserService.Save(model); Assert.IsTrue(result.Success); Assert.IsNull(result.Message); Assert.IsNotNull(result.Model); mock.RoleManagerMock.Verify(r => r.AddUserToRole(It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Exactly(2)); mock.DataSourceMock.Verify(m => m.SaveChanges(), Times.Exactly(1)); }
public void GetLockedOutListShouldReturnOnlyEntriesThatAreLockedOut() { var mock = new UserServiceMock(); var userSecurity = MembershipTestData.UserSecurity; var entry = userSecurity.First(s => s.Id == MembershipTestData.GeneralManagerId); entry.LockedOut = true; mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.DataSourceMock.Setup(d => d.Query<UserSecurity>()).Returns(userSecurity.AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny<Guid[]>())).Returns(new List<AccountStatus> { new AccountStatus { Id = MembershipTestData.GeneralManagerId, Approved = true, LockedOut = true } }); var result = mock.UserService.List(new FilterOptions { Filter = new Filter { Filters = new List<FilterField> { new FilterField { Field = "LockedOut", Value = "true" } } } }); Assert.AreEqual(1, result.Length()); Assert.AreEqual(MembershipTestData.GeneralManager.Name, (result.GetFirst() as UserListModel).Name); }
public void GetOrderedListShouldReturnAnOrderedList() { var mock = new UserServiceMock(); mock.UserManagerMock.Setup(u => u.Query()).Returns(MembershipTestData.Users.Where(u => u.Roles.Any(r => r.GroupRoleGroupId == MembershipTestData.MainGroupId)).AsQueryable()); mock.SecurityManagerMock.Setup(s => s.GetAccountStatusData(It.IsAny<Guid[]>())).Returns(new List<AccountStatus> { new AccountStatus { Id = MembershipTestData.AdminId, Approved = true, LockedOut = false }, new AccountStatus { Id = MembershipTestData.GeneralManagerId, Approved = true, LockedOut = false } }); var sortFields = new List<SortField>(); sortFields.Add(new SortField { Field = "Name", Dir = "desc" }); var result = mock.UserService.List(new FilterOptions { Sort = sortFields }); Assert.AreEqual(2, result.Length()); Assert.AreEqual(MembershipTestData.AdminName, result.Cast<UserListModel>().Last().Name); }