示例#1
0
        public void BroadcastChatMessage_NotFromAnotherGame()
        {
            Game game = new Game(0, 0, DateTime.Now, new List <Player>());

            game.ActiveGuidGame = "testguid";
            var callbackHandlerFrey           = new ChatCallbackHandler(game, new System.Windows.Controls.ListBox());
            ChatServiceClient chatServiceFrey = new ChatServiceClient(new InstanceContext(callbackHandlerFrey));

            chatServiceFrey.EnterChat("testguid", "Frey");
            Thread.Sleep(1000);

            Game game2 = new Game(0, 0, DateTime.Now, new List <Player>());

            game2.ActiveGuidGame = "testguid2";
            var callbackHandlerTester           = new ChatCallbackHandler(game2, new System.Windows.Controls.ListBox());
            ChatServiceClient chatServiceTester = new ChatServiceClient(new InstanceContext(callbackHandlerTester));

            chatServiceTester.EnterChat("testguid2", "Tester");
            Thread.Sleep(1000);

            chatServiceTester.BroadcastMessage("testguid2", "Tester", "Mensaje de prueba");
            Thread.Sleep(1000);
            Assert.AreEqual("Mensaje de prueba", callbackHandlerTester.LastMessageReceived);
            Assert.AreEqual(string.Empty, callbackHandlerFrey.LastMessageReceived);
        }
示例#2
0
        /// <summary>
        /// Establishes a connection with chat callback to enter to the game chat.
        /// </summary>
        /// <param name="game">Game to interact</param>
        /// <param name="player">Player who will enter to the game chat</param>
        /// <param name="chatListBox">Chat list box where the messages will be placed on</param>
        /// <param name="chatServiceClient">Instance where connection will be placed on</param>
        public static void JoinGameChat(Game game, Player player, System.Windows.Controls.ListBox chatListBox, ref ChatServiceClient chatServiceClient)
        {
            InstanceContext chatInstanceContext = new InstanceContext(new ChatCallbackHandler(game, chatListBox));

            chatServiceClient = new ChatServiceClient(chatInstanceContext);
            while (true)
            {
                if (player != null)
                {
                    chatServiceClient.EnterChat(game.ActiveGuidGame, player.Account.Username);
                    break;
                }
            }
        }
示例#3
0
        public void BroadcastChatMessageTest()
        {
            System.Windows.Controls.ListBox listBox = new System.Windows.Controls.ListBox();
            Game game = new Game(0, 0, DateTime.Now, new List <Player>());

            game.ActiveGuidGame = "testguid";
            var callbackHandler           = new ChatCallbackHandler(game, listBox);
            ChatServiceClient chatService = new ChatServiceClient(new InstanceContext(callbackHandler));

            chatService.EnterChat("testguid", "Frey");
            Thread.Sleep(1000);
            chatService.BroadcastMessage("testguid", "Frey", "Mensaje de prueba");
            Thread.Sleep(1000);
            Assert.AreEqual("Mensaje de prueba", callbackHandler.LastMessageReceived);
        }