Ejemplo n.º 1
0
        public void SendNamesToAll()
        {
            string      expected  = "NAMES Юзер1 Юзер2";
            UserList    ulist     = new UserList();
            FakeClient  fclient_1 = new FakeClient();
            FakeClient  fclient_2 = new FakeClient();
            TcpListener listener  = new TcpListener(IPAddress.Any, 666);

            listener.Start();
            Thread thread = new Thread(() => fclient_1.Connect());

            thread.Start();
            ulist.Add(new User(listener.AcceptTcpClient(), "Юзер1"));
            thread.Join();
            thread = new Thread(() => fclient_2.Connect());
            thread.Start();
            ulist.Add(new User(listener.AcceptTcpClient(), "Юзер2"));
            thread.Join();
            listener.Stop();

            thread = new Thread(() => ulist.SendNamesToAll());
            thread.Start();
            string result_1 = fclient_1.RecieveMessage();
            string result_2 = fclient_2.RecieveMessage();

            thread.Join();
            Assert.AreEqual(expected, result_1);
            Assert.AreEqual(expected, result_2);
        }
Ejemplo n.º 2
0
        public void Connecting()
        {
            string recMsg = fclient.RecieveMessage();
            string expMsg = "YOUARE";

            Assert.AreEqual(expMsg, recMsg.Substring(0, expMsg.Length));
            string name = recMsg.Substring(expMsg.Length + 1);

            recMsg = fclient.RecieveMessage();
            expMsg = "MSG Тебя приветствует сервер";
            Assert.AreEqual(expMsg, recMsg.Substring(0, expMsg.Length));

            recMsg = fclient.RecieveMessage();
            expMsg = "MSG " + name + " присоединился к чату.";
            Assert.AreEqual(expMsg, recMsg);

            recMsg = fclient.RecieveMessage();
            expMsg = "NAMES " + name;
            Assert.AreEqual(expMsg, recMsg);
        }
Ejemplo n.º 3
0
        public void Msg_Success()
        {
            fclient.SkipFirstMessages();
            string name1 = server.userList[0].name;

            FakeClient fclient2 = new FakeClient();

            fclient2.Connect();
            fclient2.SkipFirstMessages();
            string name2 = server.userList[1].name;

            fclient.RecieveMessage();
            fclient.RecieveMessage();
            string sendMSG = "MSG привет всем!";
            string recMSG  = "MSG " + name1 + ": привет всем!";

            fclient.SendAndRecieve(sendMSG, recMSG);

            string msg = fclient2.RecieveMessage();

            Assert.AreEqual(recMSG, msg);
        }