public void ServerDisconnectTest()
        {
            AutoResetEvent ar1 = new AutoResetEvent(false);
            AutoResetEvent ar2 = new AutoResetEvent(false);

            bool disconnected1 = false;
            bool disconnected2 = false;

            Connect4Server.Connect4Service server = new Connect4Server.Connect4Service(5008, 30, Connect4Server.Connect4Service.WhoGoesFirst.second);
            Connect4ClientGame target1 = new Connect4ClientGame("Mr. test");
            Connect4ClientGame target2 = new Connect4ClientGame("Mrs. test");
            target1.Disconnected += (r) =>
            {
                if (r == DisconnectReason.serverDisconnected)
                {
                    disconnected1 = true;
                    ar1.Set();
                }
            };

            target2.Disconnected += (r) =>
            {
                if (r == DisconnectReason.serverDisconnected)
                {
                    disconnected2 = true;
                    ar2.Set();
                }
            };

            target1.StartConnection("localhost", 5008);
            Thread.Sleep(500);
            target2.StartConnection("localhost", 5008);
            Thread.Sleep(1000);
            server.Shutdown();
            ar1.WaitOne();
            ar2.WaitOne();
            Assert.IsTrue(disconnected1);
            Assert.IsTrue(disconnected2);
        }
        public void ServerDiesAfterConnectBeforeReceiveTest()
        {
            AutoResetEvent ar1 = new AutoResetEvent(false);

            bool serverDied = false;

            Connect4Server.Connect4Service server = new Connect4Server.Connect4Service(5016, 30, Connect4Server.Connect4Service.WhoGoesFirst.first);
            Connect4ClientGame target1 = new Connect4ClientGame("Mr. test");
            target1.ConnectionEstablished += (r) =>
            {
                if (r)
                {
                    server.Shutdown();
                }
            };

            target1.Disconnected += (r) =>
            {
                if (r == DisconnectReason.serverDisconnected)
                {
                    serverDied = true;
                    ar1.Set();
                }
            };

            target1.StartConnection("localhost", 5016);
            Thread.Sleep(500);
            Thread.Sleep(1000);
            target1.CancelConnection();
            ar1.WaitOne();

            Assert.IsTrue(serverDied);
        }