Ejemplo n.º 1
0
        public void NetworkServerInitTest()
        {
            var server = StartServer();

            Assert.That(() => server.Status, Is.EqualTo(NetPeerStatus.Running).After(4).Seconds.PollEvery(100));

            StopServer(server);

            Assert.That(() => server.Status, Is.EqualTo(NetPeerStatus.NotRunning).After(4).Seconds.PollEvery(100));
            NetPeerManager.WaitForExit();
        }
Ejemplo n.º 2
0
        public void NetworkClientInitTest()
        {
            InitTestContext();
            var client = new TestClient();

            Assert.That(() => client.NetClient.Status, Is.EqualTo(NetPeerStatus.Running).After(4).Seconds.PollEvery(50));

            client.StopClient();

            Assert.That(() => client.NetClient.Status, Is.EqualTo(NetPeerStatus.NotRunning).After(4).Seconds.PollEvery(50));
            NetPeerManager.WaitForExit();
        }
Ejemplo n.º 3
0
        public void NetworkConnectDisconnect()
        {
            InitTestContext();
            TestContext.Out.WriteLine("-----------------------------------------------------------");

            var task = Task.Run(() => ServerThread());

            var clients = new List <TestClient>(1000);

            // pool 20 clients
            for (var x = 0; x < 1000; x++)
            {
                clients.Add(new TestClient());
            }

            foreach (var client in clients)
            {
                client.DoConnectTest();
            }

            task.Wait();
            NetPeerManager.WaitForExit();
        }
Ejemplo n.º 4
0
        public void GenericTestSuite()
        {
            NetPeerManager.StartNetworkThread();
            NetPeerConfiguration config = new NetPeerConfiguration("oldUnitTests");

            config.EnableUPnP = true;
            NetPeer peer = new NetPeer(config);

            peer.Start(); // needed for initialization

            TestContext.Out.WriteLine("Unique identifier is " + NetUtility.ToHexString(peer.UniqueIdentifier));

            ReadWriteTests.Run(peer);

            NetQueueTests.Run();

            MiscTests.Run(peer);

            BitVectorTests.Run();

            EncryptionTests.Run(peer);

            var om = peer.CreateMessage();

            peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
            try
            {
                peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
            }
            catch (NetException nex)
            {
                if (nex.Message != "This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently")
                {
                    throw;
                }
            }

            peer.Shutdown("bye");

            // read all message
            NetIncomingMessage inc = peer.WaitMessage(5000);

            while (inc != null)
            {
                switch (inc.MessageType)
                {
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.VerboseDebugMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.ErrorMessage:
                    TestContext.Out.WriteLine("Peer message: " + inc.ReadString());
                    break;

                case NetIncomingMessageType.Error:
                    throw new Exception("Received error message!");
                }

                inc = peer.ReadMessage();
            }

            TestContext.Out.WriteLine("Completed Generic Test Suite");
            TestContext.Out.WriteLine("----------------------------");
            NetPeerManager.WaitForExit();
        }