Esempio n. 1
0
        public void ClientDisconnects()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            bool eval = false;

            TestDefaults.WaitForCondition(() => S.ClientCount == 1);

            eval = S.ClientCount == 1;

            c.Disconnect();

            TestDefaults.WaitForCondition(() => !S.ReadonlyClients[0].IsConnected);

            eval = eval && !S.ReadonlyClients[0].IsConnected;

            Assert.True(eval);

            S.Close();
        }
Esempio n. 2
0
        public async Task ClientRecievesObjectsAsync()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            Exception e = new Exception();
            bool      b = true;
            string    s = "AFagea";

            S.SendToAll(e);
            S.SendToAll(b);
            S.SendToAll(s);

            Exception ex = await c.PullObjectAsync <Exception>();

            bool bx = await c.PullObjectAsync <bool>();

            string sx = await c.PullObjectAsync <string>();

            Assert.True(sx == s && b == bx);

            S.Close();
        }
Esempio n. 3
0
        public async Task ServerRecievesQueuesAsync()
        {
            TestDefaults.SetGlobalDefaults();

            Server s = TestDefaults.GetServer(2);

            s.StartServer();

            Client c1 = new Client();

            c1.Connect(IPAddress.Loopback, 9090);

            Client c2 = new Client();

            c2.Connect(IPAddress.Loopback, 9090);

            decimal d  = 668.7m;
            string  st = "ADGAERTYGAsfjp0ajt0qejtg0ajfgopa8484698";
            string  s2 = "F F   F F f";

            await s.SendToAllAsync(d);

            await s.SendToAllAsync(st);

            await s.SendToAllAsync(s2);

            Thread.Sleep(500);

            object[] q1 = await c1.GetQueueObjectsTypelessAsync();

            object[] q2 = await c2.GetQueueObjectsTypelessAsync();

            Assert.True(q1.Length == q2.Length);
        }
Esempio n. 4
0
        public void ServerRecievesObjects <T>(int clients, T obj)
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer(clients);

            S.StartServer();

            Client[] Clients = TestDefaults.GetClientList(() =>
            {
                Client c = new Client();
                c.Connect(IPAddress.Loopback, 9090);
                return(c);
            }, clients);

            foreach (Client c in Clients)
            {
                c.SendObject(obj);
            }

            bool b = TestDefaults.TimeOut(() =>
            {
                for (int i = 0; i < clients; i++)
                {
                    S.WaitForPullFromClient <T>((ushort)i);
                }
            }, 6000);

            Assert.True(b);

            S.Close();
        }
Esempio n. 5
0
        public async void ServerRecievesObjectsAsync <T>(int clients, T obj)
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer(clients);

            S.StartServer();

            Client[] Clients = TestDefaults.GetClientList(() =>
            {
                Client c = new Client();
                c.Connect(IPAddress.Loopback, 9090);
                return(c);
            }, clients);

            List <Task> tasks = new List <Task>();

            foreach (Client c in Clients)
            {
                tasks.Add(c.SendObjectAsync(obj));
            }

            foreach (Task t in tasks)
            {
                await t;
            }

            List <Task <T> > tasks2 = new List <Task <T> >();

            for (int i = 0; i < clients; i++)
            {
                tasks.Add(S.PullFromClientAsync <T>((ushort)i));
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            bool b = true;

            foreach (Task <T> t in tasks2)
            {
                while (sw.ElapsedMilliseconds < 3000 && !t.IsCompleted)
                {
                    ;
                }
                if (!t.Result.Equals(obj))
                {
                    b = false;
                }
            }

            Assert.True(b);

            S.Close();
        }
Esempio n. 6
0
        public async Task ClientConnectsAsync()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();
            await c.ConnectAsync(IPAddress.Loopback, 9090);

            TestDefaults.WaitForCondition(() => S.ClientCount == 1);

            Assert.True(S.ClientCount == 1);

            S.Close();
        }
Esempio n. 7
0
        public void RecievesInherited()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            var test = new TestDefaults.TestClass()
            {
                ID = 42, Foo = "foos", Str = "String"
            };

            S.SendToAll(test);
            S.SendToAll(test);
            S.SendToAll(test);
            S.SendToAll(test);

            Assert.True(TestDefaults.TimeOut(() =>
            {
                var v1 = c.WaitForPullObject <TestDefaults.TestClass>();
                var v2 = c.WaitForPullObject <TestDefaults.TestBase>();
                var v3 = c.WaitForPullObject <TestDefaults.TestInterface>();
                var v4 = c.WaitForPullObject <object>();
                while (v1.ID != 42 || v1.GetFoo() != "foos" || v1.st != "String")
                {
                    ;
                }
                while (v2.GetFoo() != "foos" || v2.GetID() != 42)
                {
                    ;
                }
                while (v3.GetVal() != 42 || v3.Str != "String")
                {
                    ;
                }
                while ((v4 as TestDefaults.TestClass).ID != 42)
                {
                    ;
                }
            }, 50000));
        }
Esempio n. 8
0
        public void ClientConnectInvokes()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.OnConnect += OnConnect;
            c.BeginConnect(IPAddress.Loopback, 9090);

            TestDefaults.WaitForCondition(() => Connections == 1);

            Assert.True(Connections == 1);

            S.Close();
        }
Esempio n. 9
0
        public async Task ClientRetrievesQueueAsync()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            Exception e = new Exception();
            bool      b = true;
            string    s = "AFagea";

            S.SendToAll(e);
            S.SendToAll(b);
            S.SendToAll(s);
            Thread.Sleep(500);

            object[] queue = await c.GetQueueObjectsTypelessAsync(true);

            bool bo = true;

            if (!queue[0].GetType().Equals(e.GetType()))
            {
                bo = false;
            }
            if (!queue[1].Equals(b))
            {
                bo = false;
            }
            if (!queue[2].Equals(s))
            {
                bo = false;
            }

            Assert.True(bo);

            S.Close();
        }
Esempio n. 10
0
        private void FileTest(Server.RecievedFile t)
        {
            TestDefaults.SetGlobalDefaults();

            Server s = TestDefaults.GetServer();

            s.OnClientRecieveFile = t;
            s.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            string path = Directory.GetCurrentDirectory();
            string f    = Directory.GetFiles(path)[0];

            c.SendFile(f);

            Assert.True(TestDefaults.WaitForCondition(() => condition));
        }
Esempio n. 11
0
        public void ClientRetrievesQueue()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            Exception e = new Exception();
            bool      b = true;
            string    s = "AFagea";

            S.SendToAll(e);
            S.SendToAll(b);
            S.SendToAll(s);
            Thread.Sleep(500);
            Assert.True(TestDefaults.WaitForCondition(() =>
            {
                object[] queue = c.GetQueueObjectsTypeless(true);

                if (!queue[0].GetType().Equals(e.GetType()))
                {
                    return(false);
                }
                if (!queue[1].Equals(b))
                {
                    return(false);
                }
                if (!queue[2].Equals(s))
                {
                    return(false);
                }
                return(true);
            }));

            S.Close();
        }
        public async void ClientSendsFileAsync()
        {
            TestDefaults.SetGlobalDefaults();

            Server s = TestDefaults.GetServer();

            s.OnClientRecieveFile = ServerFileRecieve;
            s.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            GlobalDefaults.ClearSentFiles();

            string path = Directory.GetCurrentDirectory();
            string f    = Directory.GetFiles(path)[0];
            await c.SendFileAsync(f);

            Assert.True(TestDefaults.WaitForCondition(() => files == 1));
        }
Esempio n. 13
0
        public void ServerSendsFiles()
        {
            TestDefaults.SetGlobalDefaults();

            Server s = TestDefaults.GetServer();

            s.StartServer();

            Client c = new Client();

            c.OnFileRecieve += ClientFileReceive;
            c.Connect(IPAddress.Loopback, 9090);

            GlobalDefaults.ClearSentFiles();

            string path = Directory.GetCurrentDirectory();
            string f    = Directory.GetFiles(path)[0];

            s.SendFileToAll(f);

            Assert.True(TestDefaults.WaitForCondition(() => files == 1));
        }
Esempio n. 14
0
        public void ClientDisconnectInvokes()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.StartServer();

            Client c = new Client();

            c.OnDisconnect += OnDisconnect;
            c.BeginConnect(IPAddress.Loopback, 9090);

            TestDefaults.WaitForCondition(() => S.ClientCount == 1, 5000);
            //Thread.Sleep(1000);
            S.DisconnectAllClients();

            TestDefaults.WaitForCondition(() => Disconnections == 1);

            Assert.True(Disconnections == 1);

            S.Close();
        }
Esempio n. 15
0
        public void ServerDisconnectInvokes()
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer();

            S.OnClientDisconnect += OnDisconnect;
            S.StartServer();

            Client c = new Client();

            c.Connect(IPAddress.Loopback, 9090);

            TestDefaults.WaitForCondition(() => S.ClientCount == 1);

            c.Disconnect();

            TestDefaults.WaitForCondition(() => Disconnections == 1);

            Assert.True(Disconnections == 1);

            S.Close();
        }