Esempio n. 1
0
        public void GetMatchmakingResult_ReturnMatchFound_MatchmakingResult()
        {
            try
            {
                var baseAddress = new Uri("net.tcp://localhost:8090/Contratos");
                serviceHost = new ServiceHost(typeof(Contratos.MainService), baseAddress);
                System.ServiceModel.Channels.Binding binding = new NetTcpBinding();
                var address  = new EndpointAddress("net.tcp://localhost:8090/ServerTests");
                var endpoint = serviceHost
                               .AddServiceEndpoint(typeof(Contratos.IGameManager), binding, address.Uri);

                var smb = new ServiceMetadataBehavior {
                    HttpGetEnabled = false
                };
                serviceHost.Description.Behaviors.Add(smb);
                InstanceContext instanceContext = new InstanceContext(new GameManagerCallbackHandler());
                gameClient    = new GameManagerClient(instanceContext);
                endpoint.Name = gameClient.Endpoint.Name;

                serviceHost.Open();

                Jugador testPlayer = new Jugador
                {
                    Apodo       = "pklove3456",
                    Contrasenia = "bobcholo1",
                };
                gameClient.CreateMatch(testPlayer, CheckersGameMode.ClassicCheckers);

                Jugador testPlayer2 = new Jugador
                {
                    Apodo       = "frews2",
                    Contrasenia = "frews1",
                };
                gameClient.CreateMatch(testPlayer2, CheckersGameMode.ClassicCheckers);

                GameManagerCallbackHandler gameHandler = new GameManagerCallbackHandler();
                MatchmakingResult          result      = gameHandler.matchmakingResult;

                Assert.AreEqual(result, MatchmakingResult.MATCH_FOUND);
            }
            catch (EndpointNotFoundException)
            {
                gameClient.Abort();
            }
            catch (CommunicationException)
            {
                gameClient.Abort();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Crea una solicitud para que un <c>Jugador</c> se una a una partida de juego checkers
 /// </summary>
 /// <param name="player"></param>
 /// <param name="gameMode"></param>
 /// <exception>
 /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
 /// </exception>
 public static void EnterMatchmaking(Jugador player, CheckersGameMode gameMode)
 {
     try
     {
         InstanceContext   instanceContext = new InstanceContext(new GameManagerCallbackHandler());
         GameManagerClient server          = new GameManagerClient(instanceContext);
         server.CreateMatch(player, gameMode);
     }
     catch (EndpointNotFoundException)
     {
         MessageBox.Show(Properties.Resources.NoConnectionMessage);
     }
 }