protected override Task <TextChatUser> PublicProfile(UserId id)
        {
            TextChatUser chatUser;

            switch (id)
            {
            case 1: chatUser = new TextChatUser()
            {
                    FirstName = Resources.Alice.FirstName, LastName = Resources.Alice.LastName, Knows = Resources.Alice.Knows, Learns = Resources.Alice.Learns, Id = Resources.Alice.UserId
            }; break;

            case 2: chatUser = new TextChatUser()
            {
                    FirstName = Resources.Bob.FirstName, LastName = Resources.Alice.LastName, Knows = Resources.Bob.Knows, Learns = Resources.Bob.Learns, Id = Resources.Bob.UserId
            }; break;

            case 3: chatUser = new TextChatUser()
            {
                    FirstName = Resources.Carol.FirstName, LastName = Resources.Alice.LastName, Knows = Resources.Carol.Knows, Learns = Resources.Carol.Learns, Id = Resources.Carol.UserId
            }; break;

            default: throw new Exception("Not expected User ID.");
            }
            return(Task.FromResult(chatUser));
        }
        public void Events()
        {
            var validUser = new User {
                Id = AliceUserId, Status = new UsersStatus {
                    Id = UserStatuses.Valid
                }
            };
            var sgClientMock = new Mock <IEmailSender>();
            var controller   = new TextChatController(/*sgClientMock.Object*/);
            var events       = new Queue <string>();

            var aliceChatUser = new TextChatUser {
                FirstName = AliceName, LastName = "A.", Knows = AliceKnows, Learns = AliceLearns, Id = AliceUserId
            };
            var message = new TextChatMessage {
                UserId = AliceUserId, FirstName = AliceName, RoomId = EnglishRoomId, Text = AliceMessageText, Visibility = MessageVisibility.Nobody
            };
            UserId aliceUserId = null;

            controller.OnUserJoinedRoom += (roomId, userId) => { aliceUserId = userId; events.Enqueue($"{userId} joined {roomId}"); };
            controller.OnPostedMessage  += (msg) => { events.Enqueue(msg.Text); };


            controller.JoinChat(AliceUserId, aliceChatUser);
            controller.JoinRoom(AliceUserId, EnglishRoomId);
            controller.PostTo(validUser, message).Wait();

            Assert.AreEqual($"{aliceUserId} joined {EnglishRoomId}", events.Dequeue());
            Assert.AreEqual(AliceMessageText, events.Dequeue());
            Assert.AreEqual(0, events.Count);
        }
        public void ConsecutiveJoinAndLeave()
        {
            var sgClientMock  = new Mock <IEmailSender>();
            var controller    = new TextChatController(/*sgClientMock.Object*/);
            var events        = new Queue <string>();
            var aliceChatUser = new TextChatUser()
            {
                FirstName = AliceName, LastName = "A.", Knows = AliceKnows, Learns = AliceLearns, Id = AliceUserId
            };
            UserId aliceUserId = null;

            // Listen to events
            controller.OnUserJoinedRoom += (roomId, userId) => {
                events.Enqueue($"{userId} joined {roomId}");
                aliceUserId = userId;
            };
            controller.OnUserLeftRoom += (roomId, userId) => { events.Enqueue($"{userId} left {roomId}"); };
            controller.OnUserLeft     += (userId) => { events.Enqueue($"{userId} left"); };

            // Alice's actions
            controller.JoinChat(AliceUserId, aliceChatUser);
            controller.JoinRoom(AliceUserId, EnglishRoomId);
            controller.LeaveChat(AliceUserId);

            // Check results
            Assert.AreEqual($"{aliceUserId} joined {EnglishRoomId}", events.Dequeue());
            Assert.AreEqual($"{aliceUserId} left {EnglishRoomId}", events.Dequeue());
            Assert.AreEqual($"{aliceUserId} left", events.Dequeue());

            // Alice's actions again
            controller.JoinChat(AliceUserId, aliceChatUser);
            controller.JoinRoom(AliceUserId, EnglishRoomId);
            controller.LeaveChat(AliceUserId);

            // Check results
            Assert.AreEqual($"{aliceUserId} joined {EnglishRoomId}", events.Dequeue());
            Assert.AreEqual($"{aliceUserId} left {EnglishRoomId}", events.Dequeue());
            Assert.AreEqual($"{aliceUserId} left", events.Dequeue());
            Assert.AreEqual(0, events.Count);
        }