public ADMembershipServiceTestFacade(ADMembershipService service, ADTestSupport testSupport) { _service = service; _testSupport = testSupport; var adminId = Guid.NewGuid(); ADBackend.Instance.Users.Add(new UserModel() { Username = "******", Id = adminId }); ADBackend.Instance.Roles.Add(new RoleModel() { Name = "Administrator", Id = Guid.NewGuid(), Members = new[] { adminId } }); Assert.AreEqual(1, ADBackend.Instance.Users.Count()); }
private void UpdateTeams() { foreach (var team in Teams.Select(x => new { x.Id, Name = x.Name }).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x.Name, StringComparer.OrdinalIgnoreCase))) { Teams.Remove(team.Id); } if(MembershipService == null) MembershipService = new ADMembershipService(); using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain)) { foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys) { try { using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName])) { TeamModel teamModel = new TeamModel() { Id = group.Guid.Value, Description = group.Description, Name = teamName, Members = group.GetMembers(true).Select(x => MembershipService.GetUserModel(x.Guid.Value)).ToArray() }; if (teamModel != null) { Teams.AddOrUpdate(teamModel); } } } catch (Exception ex) { LogException(ex); } } } }