private async Task AddNewUsers(int usersChanged, ITestExecutionContextInternal context) { Console.WriteLine("Adding {0} Users", usersChanged); for (var i = 0; i < usersChanged; i++) { var userNum = context.CurrentUsers + 1; var httpUser = GetNextHttpUser(userNum); await Task.Run(async() => { var user = new User(userNum, httpUser); Console.WriteLine($"Initializing User {userNum}"); try { await user.Initialize(); context.ModifyUsers(list => list.Add(user)); Console.WriteLine($"Added User {userNum}"); } catch (Exception ex) { Console.WriteLine($"Failed initializing User {userNum}"); Console.Write(ex); return; } await user.Run(result => UserIterationFinished?.Invoke(result)); }); } }
private static void RemoveUsers(int usersChanged, ITestExecutionContextInternal context) { Console.WriteLine("Removing {0} Users", usersChanged); for (var i = 0; i < usersChanged; i++) { context.ModifyUsers(list => { var user = list[list.Count - 1]; user.Stop(); list.Remove(user); }); } }