Beispiel #1
0
        public static void ClassInit(TestContext context)
        {
            // run server and client on 2 threads to simulate real world and enable bi-directinal comuncation
            context.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$ Class Init");
            // context.CurrentTestOutcome

            Task task1 = new Task(() =>
            {
                mMyGingerServer = new MyGingerServer();
                mMyGingerServer.Start();
            });

            task1.Start();

            Thread.Sleep(2000);

            Task task2 = new Task(() =>
            {
                mMyGingerClient = new MyGingerClient();
                mMyGingerClient.Connect();
            });

            task2.Start();

            Thread.Sleep(500);
        }
Beispiel #2
0
        public void VerifyClientGetUniqueGUID()
        {
            // Arrange
            Guid           EmptyGuid = new Guid();
            MyGingerClient client1   = new MyGingerClient();
            Guid           guid;

            //Act
            client1.Connect();
            guid = client1.SessionID;
            client1.Disconnect();

            //Assert
            Assert.AreNotEqual(EmptyGuid.ToString(), guid.ToString(), "GUID of client session is not empty GUID");
        }
Beispiel #3
0
        public void Run10ClientsParallel()
        {
            // Arrange
            List <Task> list = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                Task t = new Task(() =>
                {
                    Random r = new Random();
                    MyGingerClient client1 = new MyGingerClient();
                    string txt             = "Hi from Client 1";
                    NewPayLoad PL          = new NewPayLoad("Echo", txt);
                    client1.Connect();
                    for (int j = 0; j < 1000; j++)
                    {
                        NewPayLoad PLRC = client1.Send(PL);
                        string txt2     = PLRC.GetValueString();
                        if (txt != txt2)
                        {
                            throw new Exception("Error in Echo!!");
                        }

                        int sleep = r.Next(0, 20);
                        Thread.Sleep(sleep);
                    }
                    client1.Disconnect();
                });
                t.Start();
                list.Add(t);
            }


            //Act
            // Wait for all clients to complete their work
            foreach (Task t in list)
            {
                t.Wait();
            }


            //Assert
            //Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack");
            //Assert.AreEqual(txt, txt2, "txt = txt2");
        }
Beispiel #4
0
        public void ClientConnectSendClose()
        {
            // Arrange
            MyGingerClient client1 = new MyGingerClient();
            string         txt     = "Hi from Client 1";
            NewPayLoad     PL      = new NewPayLoad("Echo", txt);

            //Act
            client1.Connect();
            NewPayLoad PLRC = client1.Send(PL);
            string     txt2 = PLRC.GetValueString();

            client1.Disconnect();

            //Assert
            Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack");
            Assert.AreEqual(txt, txt2, "txt = txt2");
        }
Beispiel #5
0
        public static void ClassInit(TestContext context)
        {
            // run server and client on 2 threads to simulate real world and enable bi-directinal comuncation

            Task task1 = new Task(() =>
            {
                mMyGingerServer = new MyGingerServer();
                mMyGingerServer.Start();
            });

            task1.Start();

            Stopwatch stopwatch = Stopwatch.StartNew();

            while ((mMyGingerServer == null || !mMyGingerServer.IsReady) && stopwatch.ElapsedMilliseconds < 5000)
            {
                Thread.Sleep(100);
            }
            if (!mMyGingerServer.IsReady)
            {
                throw new Exception("Error: mMyGingerServer.IsReady false");
            }


            Task task2 = new Task(() =>
            {
                mMyGingerClient = new MyGingerClient();
                mMyGingerClient.Connect();
            });

            task2.Start();

            Stopwatch stopwatch2 = Stopwatch.StartNew();

            while ((mMyGingerClient == null || !mMyGingerClient.IsReady) && stopwatch2.ElapsedMilliseconds < 5000)
            {
                Thread.Sleep(100);
            }
            if (!mMyGingerClient.IsReady)
            {
                throw new Exception("Error: mMyGingerClient.IsReady false");
            }
        }