Пример #1
0
        /// <summary>
        /// The init client.
        /// </summary>
        /// <returns>
        /// a test client
        /// </returns>
        protected virtual TestClient InitClient()
        {
            var client = new TestClient(true);

            client.Connect("localhost", 4530, "LiteLobby");

            if (client.WaitForConnect(this.WaitTime) == false)
            {
                Assert.Fail("Didn't received init response in expected time.");
            }

            return client;
        }
Пример #2
0
 /// <summary>
 ///   The on event received.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 /// <param name = "data">
 ///   The data.
 /// </param>
 private static void OnEventReceived(TestClient client, EventData data)
 {
     Action<TestClient, EventData> received = EventReceived;
     if (received != null)
     {
         received(client, data);
     }
 }
Пример #3
0
 /// <summary>
 ///   The on response received.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 /// <param name = "response">
 ///   The response.
 /// </param>
 private static void OnResponseReceived(TestClient client, OperationResponse response)
 {
     Action<TestClient, OperationResponse> received = ResponseReceived;
     if (received != null)
     {
         received(client, response);
     }
 }
Пример #4
0
 /// <summary>
 ///   The on connected.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 private static void OnConnected(TestClient client)
 {
     Action<TestClient> connected = Connected;
     if (connected != null)
     {
         connected(client);
     }
 }
Пример #5
0
 /// <summary>
 ///   invokes <see cref = "Disconnected" />.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 private static void OnDisonnected(TestClient client)
 {
     Action<TestClient> handler = Disonnected;
     if (handler != null)
     {
         handler(client);
     }
 }
 /// <summary>
 ///   The on init response received.
 /// </summary>
 /// <param name = "obj">
 ///   The obj.
 /// </param>
 protected void OnInitResponseReceived(TestClient obj)
 {
     int count = Interlocked.Increment(ref this.initResponseCount);
     if (count == ClientCount)
     {
         this.AutoResetEventInit.Set();
     }
 }
        /// <summary>
        ///   The on operation response received.
        /// </summary>
        /// <param name = "arg1">
        ///   The arg 1.
        /// </param>
        /// <param name = "arg2">
        ///   The arg 2.
        /// </param>
        protected void OnOperationResponseReceived(TestClient arg1, OperationResponse arg2)
        {
            int count = Interlocked.Increment(ref this.operationResponseCount);

            if (this.testNr == 1)
            {
                if (count % ClientCount == 0 && (count / ClientCount) % WaitSteps == 0)
                {
                    Console.WriteLine("set: " + count);
                    this.AutoResetEventOperation.Set();
                }
                else if (count == ClientCount * LoopCount)
                {
                    Console.WriteLine("final set: " + count);
                    this.AutoResetEventOperation.Set();
                }

                return;
            }

            if (this.testNr == 2)
            {
                if (count == ClientCount * LoopCount)
                {
                    Console.WriteLine("final set: " + count);
                    this.AutoResetEventOperation.Set();
                }
            }
        }
 /// <summary>
 ///   The on event received.
 /// </summary>
 /// <param name = "arg1">
 ///   The arg 1.
 /// </param>
 /// <param name = "arg2">
 ///   The arg 2.
 /// </param>
 protected void OnEventReceived(TestClient arg1, EventData arg2)
 {
     this.AutoResetEventEvent.Set();
 }
Пример #9
0
        /// <summary>
        ///   The leave clients from room.
        /// </summary>
        /// <param name = "client1">
        ///   The client 1.
        /// </param>
        /// <param name = "client2">
        ///   The client 2.
        /// </param>
        protected void LeaveClientsFromRoom(TestClient client1, TestClient client2)
        {
            var request = new OperationRequest { OperationCode = (byte)OperationCode.Leave, Parameters = new Dictionary<byte, object>() };
            client1.SendOperationRequest(request);
            OperationResponse response = client1.WaitForOperationResponse(this.WaitTime);
            CheckDefaultOperationParameters(response, OperationCode.Leave);

            if (client2 != null)
            {
                EventData eventArgs2 = client2.WaitForEvent(this.WaitTime);
                CheckDefaultEventParameters(eventArgs2, OperationCode.Leave, 1);

                client2.SendOperationRequest(request);
                response = client2.WaitForOperationResponse(this.WaitTime);
                CheckDefaultOperationParameters(response, OperationCode.Leave);
            }
        }
Пример #10
0
        /// <summary>
        ///   The join clients to room.
        /// </summary>
        /// <param name = "roomName">
        ///   The room name.
        /// </param>
        /// <param name = "client1">
        ///   The client 1.
        /// </param>
        /// <param name = "client2">
        ///   The client 2.
        /// </param>
        /// <param name = "clientProperties1">
        ///   The client properties 1.
        /// </param>
        /// <param name = "clientProperties2">
        ///   The client properties 2.
        /// </param>
        /// <param name = "broadcastClientProperties">
        ///   The broadcast client properties.
        /// </param>
        protected void JoinClientsToRoom(
            string roomName, TestClient client1, TestClient client2, Hashtable clientProperties1, Hashtable clientProperties2, bool broadcastClientProperties)
        {
            // send join operation for client one
            OperationRequest request = CreateJoinRequest(roomName, clientProperties1, broadcastClientProperties);
            client1.SendOperationRequest(request);

            // wait for operation response and join event
            OperationResponse response = client1.WaitForOperationResponse(this.WaitTime);
            EventData eventArgs1 = client1.WaitForEvent(this.WaitTime);

            // check operation response
            CheckJoinResponse(response, 1);

            // check join event
            Hashtable expectedActorProperties = broadcastClientProperties ? clientProperties1 : null;
            CheckJoinEvent(eventArgs1, 1, expectedActorProperties);

            if (client2 != null)
            {
                // send join operation for client two
                request = CreateJoinRequest(roomName, clientProperties2, broadcastClientProperties);
                client2.SendOperationRequest(request);

                // wait for operation response and join events
                response = client2.WaitForOperationResponse(this.WaitTime);
                eventArgs1 = client1.WaitForEvent(this.WaitTime);
                EventData eventArgs2 = client2.WaitForEvent(this.WaitTime);

                // check operation response
                CheckJoinResponse(response, 2);

                // check join events
                expectedActorProperties = broadcastClientProperties ? clientProperties2 : null;
                CheckJoinEvent(eventArgs1, 2, expectedActorProperties);
                CheckJoinEvent(eventArgs2, 2, expectedActorProperties);
            }
        }
Пример #11
0
 /// <summary>
 ///   The join clients to room.
 /// </summary>
 /// <param name = "roomName">
 ///   The room name.
 /// </param>
 /// <param name = "client1">
 ///   The client 1.
 /// </param>
 /// <param name = "client2">
 ///   The client 2.
 /// </param>
 protected void JoinClientsToRoom(string roomName, TestClient client1, TestClient client2)
 {
     this.JoinClientsToRoom(roomName, client1, client2, null, null, false);
 }
Пример #12
0
        /// <summary>
        ///   The init client.
        /// </summary>
        /// <returns>
        ///   the test client
        /// </returns>
        protected virtual TestClient InitClient()
        {
            var client = new TestClient(Settings.UseTcp);
            client.Connect(Settings.ServerAddress, Settings.Port, "Lite");

            if (client.WaitForConnect(this.WaitTime) == false)
            {
                Assert.Fail("Didn't received init response in expected time.");
            }

            return client;
        }