コード例 #1
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
        public void BoggleClientTest3()
        {
            string[] args = { "30", "..\\..\\..\\Resources\\dictionary.txt" };
            new BoggleServer.BoggleServer(args);
            BoggleClientModel player1 = new BoggleClientModel();

            player1.setBoard("ABCDEFGHIJKLMNOP");
            Assert.AreEqual("ABCDEFGHIJKLMNOP", player1.getBoard());
            player1.setPlayerName("BASIL");
            Assert.AreEqual("BASIL", player1.getPlayerName());
            player1.setPlayerScore("100");
            Assert.AreEqual("100", player1.getPlayerScore());
            player1.setOpponent("LANCE");
            Assert.AreEqual("LANCE", player1.getOpponent());
            player1.setOpponentScore("0");
            Assert.AreEqual("0", player1.getOpponentScore());
            player1.setTime("500");
            Assert.AreEqual("500", player1.getTime());
        }
コード例 #2
0
ファイル: BoggleClientTest.cs プロジェクト: rensk63/cs-3500
            public void run()
            {
                BoggleServer.BoggleServer server    = null;
                BoggleClientModel         clientOne = null;
                BoggleClientModel         clientTwo = null;

                try
                {
                    string[] args = { "20", "../../../Resources/dictionary.txt", "jimiergsatnesaps" };
                    server = new BoggleServer.BoggleServer(args);

                    // create player one connection
                    clientOne = new BoggleClientModel();
                    clientOne.Connect("localhost");

                    // create player two connection
                    clientTwo = new BoggleClientModel();
                    clientTwo.Connect("localhost");

                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    // have player one join the boggle game
                    clientOne.SendPlayerName("Basil");
                    // have player two join the boggle game
                    clientTwo.SendPlayerName("Lance");

                    // waits for one second, expecting the callback to trigger the mre1 signal
                    Assert.IsTrue(mre1.WaitOne(1000));
                    Assert.AreEqual("JIMIERGSATNESAPS", clientOne.getBoard());
                    Assert.AreEqual("BASIL", clientOne.getPlayerName());

                    // waits for one second, expecting the callback to trigger the mre2 signal
                    Assert.IsTrue(mre2.WaitOne(1000));
                    Assert.AreEqual("JIMIERGSATNESAPS", clientTwo.getBoard());
                    Assert.AreEqual("LANCE", clientTwo.getPlayerName());

                    //Reset the mres
                    mre1.Reset();
                    mre2.Reset();


                    //Check that the timer is working correctly
                    for (int i = 0; i < 29; i++)
                    {
                        mre1.Reset();
                        mre2.Reset();
                    }

                    clientOne.SendWord("to");
                    clientOne.SendWord("sap");
                    clientOne.SendWord("seat");
                    clientOne.SendWord("sat");

                    Thread.Sleep(11000);

                    clientTwo.SendWord("to");
                    clientTwo.SendWord("sap");
                    clientTwo.SendWord("irta");
                    clientTwo.SendWord("rat");

                    //add one for to
                    messagesReceivedOne.Add("SCORE " + 1 + " " + 0);
                    messagesReceivedOne.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedOne.Add("SCORE " + 1 + " " + 0);

                    //add one for to
                    messagesReceivedTwo.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedTwo.Add("SCORE " + 0 + " " + 0);
                    messagesReceivedTwo.Add("SCORE " + 1 + " " + 0);

                    Thread.Sleep(11000);

                    ////Do asserts
                    //// waits for one second, expecting the callback to trigger the mre1 signal
                    //Assert.IsTrue(mre1.WaitOne(1000));
                    //Assert.AreEqual("STOP 1 sat 1 rat 1 sap 1 seat 1 irta", s1);

                    //// waits for one second, expecting the callback to trigger the mre2 signal
                    //Assert.IsTrue(mre2.WaitOne(1000));
                    //Assert.AreEqual("STOP 1 rat 1 sat 1 sap 1 irta 1 seat", s2);
                }
                finally
                {
                    server.Stop();
                    clientOne.Disconnect();
                    clientTwo.Disconnect();
                }
            }