Ejemplo n.º 1
0
        public void TestAddingUserWithoutUserId()
        {
            var hubUser = new FakeHubUser(string.Empty, "123", "12").Build();

            _manageHubUser.AddUser(hubUser);

            var userInDb = _hubUserContext.ConnectedUsers.Where(u => u.ConnectionId == hubUser.ConnectionId).SingleOrDefault();

            Assert.Equal(hubUser.ConnectionId, userInDb.ConnectionId);
            Assert.Equal(hubUser.GroupName, userInDb.GroupName);
        }
Ejemplo n.º 2
0
        private List <HubUser> PrepareHubUsers()
        {
            var hubUser = new FakeHubUser("1", "123", "12").BuildAsList();

            hubUser.Add(new FakeHubUser("2", "234", "12").Build());
            hubUser.Add(new FakeHubUser("1", "345", "12").Build());
            hubUser.Add(new FakeHubUser(string.Empty, "456", "12").Build());
            hubUser.Add(new FakeHubUser("5", "789", "12").Build());
            hubUser.Add(new FakeHubUser(string.Empty, "567", "12").Build());
            hubUser.Add(new FakeHubUser("3", "678", "12").Build());
            return(hubUser);
        }
Ejemplo n.º 3
0
        public async void TestAddingSingleUserAsync(string userId, string connectionId, string groupName)
        {
            var hubUser = new FakeHubUser(userId, connectionId, groupName).Build();
            await _manageHubUser.AddUserAsync(hubUser);

            var userInDb            = _hubUserContext.ConnectedUsers.Where(u => u.ConnectionId == hubUser.ConnectionId).Single();
            var connectedUsersCount = _hubUserContext.ConnectedUsers.ToList().Count();
            var waitingUsersCount   = _hubUserContext.WaitingUsers.ToList().Count();

            Assert.Equal(userInDb.UserId, hubUser.UserId);
            Assert.Equal(userInDb.ConnectionId, hubUser.ConnectionId);
            Assert.Equal(userInDb.GroupName, hubUser.GroupName);
            Assert.Equal(1, connectedUsersCount);
            Assert.Equal(0, waitingUsersCount);
        }
Ejemplo n.º 4
0
        public void TestAddingTwoUsersToSameGroup()
        {
            var hubUser1 = new FakeHubUser("1", "123", "12").Build();
            var hubUser2 = new FakeHubUser("2", "234", "12").Build();

            _manageHubUser.AddUser(hubUser1);
            _manageHubUser.AddUser(hubUser2);

            var userInConnectedList = _hubUserContext.ConnectedUsers.Where(u => u.UserId == hubUser1.UserId).Single();
            var userInWaitingList   = _hubUserContext.WaitingUsers.Where(u => u.UserId == hubUser2.UserId).Single();
            var connectedUsersCount = _hubUserContext.ConnectedUsers.ToList().Count();
            var waitingUsersCount   = _hubUserContext.WaitingUsers.ToList().Count();

            Assert.Equal(hubUser1.ConnectionId, userInConnectedList.ConnectionId);
            Assert.Equal(hubUser2.ConnectionId, userInWaitingList.ConnectionId);
            Assert.Equal(1, connectedUsersCount);
            Assert.Equal(1, waitingUsersCount);
        }
Ejemplo n.º 5
0
        public async void TestAddingAndRemovingUserAsync()
        {
            var hubUser = new FakeHubUser("1", "123", "12").Build();

            await _manageHubUser.AddUserAsync(hubUser);

            var userToRemove = _manageHubUser.GetUserByConnectionId(hubUser.ConnectionId);
            await _manageHubUser.RemoveUserAsync(userToRemove);

            var  userInDb  = _hubUserContext.ConnectedUsers.Where(u => u.ConnectionId == userToRemove.ConnectionId).SingleOrDefault();
            var  userCount = _hubUserContext.ConnectedUsers.ToList().Count;
            bool result    = false;

            if (userInDb == null)
            {
                result = true;
            }

            Assert.True(result);
            Assert.Equal(0, userCount);
        }
Ejemplo n.º 6
0
        public async void TestRemovingSingleWaitingUserAsync()
        {
            var hubUser = new FakeHubUser("1", "123", "12").Build();

            _hubUserContext.WaitingUsers.Add(_mapper.Map <WaitingHubUser>(hubUser));
            _hubUserContext.SaveChanges();
            var userFromDb = _hubUserContext.WaitingUsers.Where(u => u.ConnectionId == u.ConnectionId).SingleOrDefault();

            await _manageHubUser.RemoveUserAsync(_mapper.Map <HubUser>(userFromDb));

            var  userInDb         = _hubUserContext.WaitingUsers.Where(u => u.ConnectionId == userFromDb.ConnectionId).SingleOrDefault();
            var  waitingUserCount = _hubUserContext.WaitingUsers.ToList().Count;
            bool result           = false;

            if (userInDb == null)
            {
                result = true;
            }

            Assert.True(result);
            Assert.Equal(0, waitingUserCount);
        }