public override void RunActualTest()
        {
            using (DocumentStore)
            {
                //ForclyCleanUsers();
                ReportInfo("Creating root user");
                _rootUser = GenerateRandomUser();
                AuthorizedSession.CreateRootUser(DocumentStore, _rootUser.Id, _rootUser.Password);
                using (var session = AuthorizedSession.OpenSession(DocumentStore, _rootUser.Id, _rootUser.Password))
                {
                    ReportInfo("Creating groups with members");
                    GenerateGroups(session);
                    ReportInfo("Creating orphan users");
                    GenerateOrphanUsers(session);
                }

                try
                {
                    CleanupTestsEntities();
                }
                catch (Exception e)
                {
                    //We already cleaned the data
                    ReportInfo("Exception cleaning up: " + e);
                }

                ReportSuccess("Test was completed successfully");
            }
        }
        private TestGroup GenerateGroup(AuthorizedSession session, string parent, string description = null)
        {
            var groupNumber = _numberOfGroups++;
            var groupName   = "Group/" + groupNumber;
            var group       = new TestGroup
            {
                Description = description ?? $"Group {groupNumber}",
                Id          = groupName,
                Members     = new HashSet <string>(),
                Permission  = new Permission
                {
                    Collections = new HashSet <string> {
                        $"Group{groupNumber}Only"
                    },
                    Description = $"Allows access to Group{groupNumber} related documents",
                    Ids         = new HashSet <string>()
                },
                Parent = parent
            };

            AllGroups.Add(group);
            session.CreateGroup(group.Id, group.Parent, group.Description, group.Permission);

            GenerateMembersForGroup(session, groupName);
            return(group);
        }
 private void GenerateOrphanUsers(AuthorizedSession session)
 {
     for (var i = 0; i < 1000; i++)
     {
         OrphanUsers.Add(GenerateRandomUser());
     }
 }
        private void GenerateMembersForGroup(AuthorizedSession session, string groupName)
        {
            var random          = new Random(GetStableHashCode(groupName));
            var numberOfMembers = random.Next(50, 100);

            for (int i = 0; i < numberOfMembers; i++)
            {
                var user = GenerateRandomUser();
                session.CreateUser(user.Id, user.Password);
                session.AddUserToGroup(user.Id, groupName);
                user.Groups.Add(groupName);
            }
        }
        private void GenerateGroups(AuthorizedSession session)
        {
            _rootGroup = GenerateGroup(session, null, "Root group");
            var prevLevelGroups = new[] { _rootGroup };

            for (var numberOfLevels = 0; numberOfLevels < 3; numberOfLevels++)
            {
                var nextLevelGroups = new List <TestGroup>();
                for (var i = 0; i < prevLevelGroups.Length; i++)
                {
                    var currGroup         = prevLevelGroups[i];
                    var rand              = new Random(GetStableHashCode(currGroup.Id));
                    var numberOfSubGroups = rand.Next(2, 4);
                    for (var j = 0; j < numberOfSubGroups; j++)
                    {
                        nextLevelGroups.Add(GenerateGroup(session, currGroup.Id));
                    }
                }

                prevLevelGroups = nextLevelGroups.ToArray();
            }
        }