Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
 /// <summary>
 /// Handles ChatMessageTextBox key enter down. Sends through network a chat message.
 /// </summary>
 /// <param name="sender">TextBox object</param>
 /// <param name="e">TextBox key event</param>
 private void ChatMessageTextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         if (string.IsNullOrWhiteSpace(chatMessageTextBox.Text))
         {
             return;
         }
         EngineNetwork.DoNetworkOperation <CommunicationException>(onExecute: () => {
             Application.Current.Dispatcher.Invoke(delegate {
                 chatService.BroadcastMessage(game.ActiveGuidGame, player.Account.Username, chatMessageTextBox.Text);
                 chatMessageTextBox.Clear();
             });
             return(true);
         });
     }
 }