示例#1
0
        private static void CheckDataTransfer(ITransportConnection a, ITransportConnection b)
        {
            var data = Encoding.UTF8.GetBytes("this is some test data");

            var taska = Task.Factory.StartNew(() =>
            {
                var n = a.Write(data, 0, data.Length);

                Assert.That(n, Is.EqualTo(data.Length));

                var buf = new byte[data.Length];
                n       = a.Read(buf, 0, buf.Length);
                Assert.That(n, Is.EqualTo(buf.Length));
            });

            var taskb = Task.Factory.StartNew(() =>
            {
                var buf = new byte[data.Length];
                var n   = b.Read(buf, 0, buf.Length);
                Assert.That(n, Is.EqualTo(buf.Length));

                n = b.Write(data, 0, data.Length);
                Assert.That(n, Is.EqualTo(data.Length));
            });

            Task.WaitAll(taska, taskb);
        }