public void TestRemovingSingleConnectedUser() { var hubUser = new FakeHubUser("1", "123", "12").Build(); _hubUserContext.ConnectedUsers.Add(_mapper.Map <ConnectedHubUser>(hubUser)); _hubUserContext.SaveChanges(); var userFromDb = _hubUserContext.ConnectedUsers.Where(u => u.ConnectionId == u.ConnectionId).SingleOrDefault(); _manageHubUser.RemoveUser(_mapper.Map <HubUser>(userFromDb)); var userInDb = _hubUserContext.ConnectedUsers.Where(u => u.ConnectionId == userFromDb.ConnectionId).SingleOrDefault(); var userCount = _hubUserContext.ConnectedUsers.ToList().Count; bool result = false; if (userInDb == null) { result = true; } Assert.True(result); Assert.Equal(0, userCount); }
public void AddUser(HubUser user) { var userToSave = _mapper.Map <ConnectedHubUser>(user); if (_hubUser.ConnectedUsers.Where(u => u.GroupName == user.GroupName && !String.IsNullOrEmpty(u.UserId)).FirstOrDefault() == null) { _hubUser.ConnectedUsers.Add(userToSave); } else if (_hubUser.ConnectedUsers.Where(u => u.UserId == user.UserId && u.GroupName == user.GroupName).FirstOrDefault() != null) { _hubUser.ConnectedUsers.Add(userToSave); } else if (String.IsNullOrEmpty(user.UserId) && !String.IsNullOrEmpty(user.GroupName)) { _hubUser.ConnectedUsers.Add(userToSave); } else { var waitingUserToSave = _mapper.Map <WaitingHubUser>(user); _hubUser.WaitingUsers.Add(waitingUserToSave); } _hubUser.SaveChanges(); }