Exemplo n.º 1
0
        public void GetLoginResult_ReturnLOGGEDPLAYER_LoginResult()
        {
            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.IPlayerManager), binding, address.Uri);

                var smb = new ServiceMetadataBehavior {
                    HttpGetEnabled = false
                };
                serviceHost.Description.Behaviors.Add(smb);
                InstanceContext instanceContext = new InstanceContext(new PlayerCallbackHandler());
                playerClient  = new PlayerManagerClient(instanceContext);
                endpoint.Name = playerClient.Endpoint.Name;

                serviceHost.Open();

                Jugador testPlayer = new Jugador
                {
                    Apodo       = "pklove3456",
                    Contrasenia = "bobcholo1"
                };

                playerClient.Login(testPlayer);
                playerClient.Login(testPlayer);
                PlayerCallbackHandler playerHandler = new PlayerCallbackHandler();
                LoginResult           result        = playerHandler.loginResult;

                Assert.AreEqual(result, LoginResult.LOGGED_PLAYER);
            }
            catch (EndpointNotFoundException)
            {
                playerClient.Abort();
            }
            catch (CommunicationException)
            {
                playerClient.Abort();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Crea una solicitud al servidor para iniciar sesion al sistema para un <c>Jugador</c>
        /// </summary>
        /// <param name="jugador"></param>
        /// <exception>
        /// Esta excepcion puede retornar una excepcion tipo EndpointNotFoundException
        /// </exception>
        public static void Login(Jugador jugador)
        {
            InstanceContext     instanceContext = new InstanceContext(new PlayerCallbackHandler());
            PlayerManagerClient server          = new PlayerManagerClient(instanceContext);

            try
            {
                server.Login(jugador);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show("No se ha podido conectar a la Base de datos, intentar mas tarde");
            }
        }