private void RemoveInThread(HubGroupManager <string> roleManager, int from, int to) { for (int i = from; i < to; i++) { roleManager.RemoveFromGroup($"User{i}", "Connection"); } }
private void AddInThread(HubGroupManager <string> roleManager, int from, int to) { for (int i = from; i < to; i++) { roleManager.AddToGroup("User", $"User{i}", "Connection"); } }
public SignalRHub( ILogger <SignalRHub> logger, UserManager <dotnet_react.Models.ApplicationUser> userManager, HubGroupManager appData ) { Logger = logger; UserManager = userManager; _hubGroupManager = appData; }
public void Add_whenCalled_addTwoUsers() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "thirdConnection"); roleManager.AddToGroup("User", "User1", "firstConnection"); roleManager.AddToGroup("User", "User2", "secondConnection"); Assert.AreEqual(2, roleManager.GetUsersFromGroup("User").Count()); }
public void Add_WhenCalled_CountUsersWithThreeConnectionId() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "firstConnection"); roleManager.AddToGroup("User", "User1", "secondConnection"); roleManager.AddToGroup("User", "User1", "thirdConnection"); Assert.AreEqual(1, roleManager?.GetUsersFromGroup("User").Count()); Assert.AreEqual(3, roleManager.GetUsersFromGroup("User") .FirstOrDefault().ConnectionIds.Count); }
public void GetUserGroupById_WhenCalled_ReturnEnumerableOfUsersGroup() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "firstConnection"); roleManager.AddToGroup("Admin", "User1", "firstConnection"); roleManager.AddToGroup("Coach", "User2", "secondConnection"); roleManager.AddToGroup("User", "User2", "secondConnection"); var groups = roleManager.GetUserGroupsById("User2").ToList(); Assert.IsTrue(groups.Contains("Coach") && groups.Contains("User")); }
public void Add_addUsersInThread_addTwoUsers() { var roleManager = new HubGroupManager <string>(); Thread t1 = new Thread(() => AddInThread(roleManager, 0, 1000)); Thread t2 = new Thread(() => AddInThread(roleManager, 1000, 1500)); t1.Start(); t2.Start(); t2.Join(); t1.Join(); var users = roleManager.GetUsersFromGroup("User"); Assert.AreEqual(1500, users.Count()); }
public void GetUserFromGroup_WhenCalled_ReturnEnumerableOfUsers() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "firstConnection"); roleManager.AddToGroup("Admin", "User1", "firstConnection"); roleManager.AddToGroup("Coach", "User2", "secondConnection"); roleManager.AddToGroup("User", "User2", "secondConnection"); var groups = roleManager.GetUsersFromGroup("User"); var test = roleManager.GetUsersFromGroup("NotExist"); Assert.IsEmpty(test); Assert.IsTrue(groups.Count() == 2); }
public void AddandRemove_addUsersInThread_addTwoUsers() { var roleManager = new HubGroupManager <string>(); Thread t1 = new Thread(() => AddInThread(roleManager, 0, 1000)); Thread t2 = new Thread(() => RemoveInThread(roleManager, 0, 500)); t1.Start(); t2.Start(); t1.Join(); t2.Join(); var users = roleManager.GetUsersFromGroup("User"); Assert.That(users.Count(), Is.LessThan(1000)); }
public void Remove_RemoveAllUsersFromGroup_GroupIsDeleted_AssertFalse() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "thirdConnection"); roleManager.AddToGroup("Admin", "User1", "firstConnection"); roleManager.AddToGroup("Coach", "User2", "secondConnection"); roleManager.AddToGroup("User", "User2", "secondConnection"); roleManager.RemoveFromGroup("User1", "thirdConnection"); roleManager.RemoveFromGroup("User2", "secondConnection"); var result = roleManager.IsGroupExist("User"); Assert.IsFalse(result); }
public void Remove_RemoveUserConnection_UserIsNotDeleteIfConnectionExsist() { var roleManager = new HubGroupManager <string>(); roleManager.AddToGroup("User", "User1", "thirdConnection"); roleManager.AddToGroup("User", "User1", "firstConnection"); roleManager.AddToGroup("User", "User2", "secondConnection"); roleManager.RemoveFromGroup("User1", "thirdConnection"); var user = roleManager.GetUsersFromGroup("User") .FirstOrDefault(x => x.UserId == "User1"); bool result = user != null; Assert.IsTrue(result); }